Class: CCS::Components::GovUK::FormGroup
- Defined in:
- lib/ccs/components/govuk/form_group.rb
Overview
GOV.UK FormGroup
This helper is used for generating the form group component from the Government Design Systems
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
The default attributes for the form group
{ class: 'govuk-form-group' }.freeze
Instance Method Summary collapse
-
#initialize(attribute:, error_message: nil, **options) ⇒ FormGroup
constructor
A new instance of FormGroup.
-
#render {|displayed_error_message| ... } ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Form Group component.
Constructor Details
#initialize(attribute:, error_message: nil, **options) ⇒ FormGroup
Returns a new instance of FormGroup.
30 31 32 33 34 35 36 37 38 |
# File 'lib/ccs/components/govuk/form_group.rb', line 30 def initialize(attribute:, error_message: nil, **) super(**) @options[:attributes][:id] ||= "#{attribute}-form-group" @options[:attributes][:class][..15] = 'govuk-form-group govuk-form-group--error' if @attribute = attribute @error_message = end |
Instance Method Details
#render {|displayed_error_message| ... } ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Form Group component
48 49 50 51 52 |
# File 'lib/ccs/components/govuk/form_group.rb', line 48 def render tag.div(**[:attributes]) do yield((ErrorMessage.new(message: , attribute: attribute, context: context).render if )) end end |