Class: Practical::Views::Form::InputComponent
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- Practical::Views::Form::InputComponent
- Defined in:
- app/components/practical/views/form/input_component.rb
Defined Under Namespace
Classes: FieldOptionsNotCalledError
Instance Attribute Summary collapse
-
#f ⇒ Object
Returns the value of attribute f.
-
#label_options ⇒ Object
Returns the value of attribute label_options.
-
#object_method ⇒ Object
Returns the value of attribute object_method.
Instance Method Summary collapse
- #around_render ⇒ Object
- #field_errors_id ⇒ Object
- #field_options(**options) ⇒ Object
-
#initialize(f:, object_method:, label_options: {}) ⇒ InputComponent
constructor
A new instance of InputComponent.
Constructor Details
#initialize(f:, object_method:, label_options: {}) ⇒ InputComponent
Returns a new instance of InputComponent.
10 11 12 13 14 |
# File 'app/components/practical/views/form/input_component.rb', line 10 def initialize(f:, object_method:, label_options: {}) self.f = f self.object_method = object_method self. = end |
Instance Attribute Details
#f ⇒ Object
Returns the value of attribute f.
5 6 7 |
# File 'app/components/practical/views/form/input_component.rb', line 5 def f @f end |
#label_options ⇒ Object
Returns the value of attribute label_options.
5 6 7 |
# File 'app/components/practical/views/form/input_component.rb', line 5 def @label_options end |
#object_method ⇒ Object
Returns the value of attribute object_method.
5 6 7 |
# File 'app/components/practical/views/form/input_component.rb', line 5 def object_method @object_method end |
Instance Method Details
#around_render ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/components/practical/views/form/input_component.rb', line 28 def around_render result = yield unless @_field_options_called raise FieldOptionsNotCalledError, "field_options was not called when rendering an InputComponent; which means this the input & its error container are not connected." end return result end |
#field_errors_id ⇒ Object
16 17 18 |
# File 'app/components/practical/views/form/input_component.rb', line 16 def field_errors_id f.field_errors_id(object_method) end |
#field_options(**options) ⇒ Object
20 21 22 23 24 25 26 |
# File 'app/components/practical/views/form/input_component.rb', line 20 def (**) @_field_options_called = true return mix({ "aria-describedby": field_errors_id, "data": {"pf-initial-load-errors": f.errors_for(object_method)&.any? } }, ) end |