Class: GOVUKDesignSystemFormBuilder::Base
- Inherits:
-
Object
- Object
- GOVUKDesignSystemFormBuilder::Base
- Defined in:
- lib/govuk_design_system_formbuilder/base.rb
Direct Known Subclasses
Containers::ButtonGroup, Containers::CheckBoxes, Containers::CheckBoxesFieldset, Containers::Fieldset, Containers::FormGroup, Containers::RadioButtonsFieldset, Containers::Radios, Containers::Supplemental, Elements::Caption, Elements::CheckBoxes::Collection, Elements::CheckBoxes::CollectionCheckBox, Elements::CheckBoxes::FieldsetCheckBox, Elements::CheckBoxes::Label, Elements::CollectionSelect, Elements::Date, Elements::ErrorMessage, Elements::ErrorSummary, Elements::File, Elements::Hint, Elements::Inputs::Email, Elements::Inputs::Number, Elements::Inputs::Phone, Elements::Inputs::Text, Elements::Inputs::URL, Elements::Label, Elements::Legend, Elements::Null, Elements::Password, Elements::Radios::Collection, Elements::Radios::CollectionRadioButton, Elements::Radios::FieldsetRadioButton, Elements::Select, Elements::Submit, Elements::TextArea, Proxy
Instance Method Summary collapse
-
#field_id(link_errors: false) ⇒ String
returns the id value used for the input.
-
#initialize(builder, object_name, attribute_name, &block) ⇒ Base
constructor
A new instance of Base.
-
#to_s ⇒ Object
objects that implement #to_s can be passed directly into #safe_join.
Constructor Details
#initialize(builder, object_name, attribute_name, &block) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 |
# File 'lib/govuk_design_system_formbuilder/base.rb', line 6 def initialize(builder, object_name, attribute_name, &block) @builder = builder @object_name = object_name @attribute_name = attribute_name @block_content = capture { block.call } if block_given? end |
Instance Method Details
#field_id(link_errors: false) ⇒ String
field_id is overridden so that the error summary can link to the correct element.
It’s straightforward for inputs with a single element (like a textarea or text input) but the GOV.UK Design System requires that the error summary link to the first checkbox or radio in a list, so additional logic is requred
returns the id value used for the input
31 32 33 34 35 36 37 |
# File 'lib/govuk_design_system_formbuilder/base.rb', line 31 def field_id(link_errors: false) if link_errors && has_errors? build_id('field-error', include_value: false) else build_id('field') end end |
#to_s ⇒ Object
objects that implement #to_s can be passed directly into #safe_join
14 15 16 |
# File 'lib/govuk_design_system_formbuilder/base.rb', line 14 def to_s html || '' end |