Class: CCS::Components::GovUK::Field
- Defined in:
- lib/ccs/components/govuk/field.rb,
lib/ccs/components/govuk/field/input.rb,
lib/ccs/components/govuk/field/inputs.rb,
lib/ccs/components/govuk/field/inputs/item.rb,
lib/ccs/components/govuk/field/input/select.rb,
lib/ccs/components/govuk/field/inputs/radios.rb,
lib/ccs/components/govuk/field/input/textarea.rb,
lib/ccs/components/govuk/field/input/text_input.rb,
lib/ccs/components/govuk/field/input/file_upload.rb,
lib/ccs/components/govuk/field/inputs/checkboxes.rb,
lib/ccs/components/govuk/field/inputs/date_input.rb,
lib/ccs/components/govuk/field/inputs/item/radio.rb,
lib/ccs/components/govuk/field/inputs/item/divider.rb,
lib/ccs/components/govuk/field/input/password_input.rb,
lib/ccs/components/govuk/field/input/text_input/fix.rb,
lib/ccs/components/govuk/field/inputs/item/checkbox.rb,
lib/ccs/components/govuk/field/input/character_count.rb,
lib/ccs/components/govuk/field/inputs/item/radio/tag.rb,
lib/ccs/components/govuk/field/inputs/date_input/item.rb,
lib/ccs/components/govuk/field/inputs/item/radio/form.rb,
lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb,
lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb,
lib/ccs/components/govuk/field/input/character_count/count_message.rb,
lib/ccs/components/govuk/field/input/password_input/show_hide_button.rb
Overview
GOV.UK Field
This class is used to create a form using the structure of a GDS input field components, e.g. text input. It will wrap the input within the form group as well as find if there are any error messages to display.
Defined Under Namespace
Constant Summary
Constants inherited from Base
Instance Method Summary collapse
-
#initialize(attribute:, form_group: nil, hint: nil, before_input: nil, after_input: nil, **options) ⇒ Field
constructor
A new instance of Field.
-
#render {|displayed_error_message| ... } ⇒ ActiveSupport::SafeBuffer
Generates the HTML to wrap arround a GDS form input component.
Constructor Details
#initialize(attribute:, form_group: nil, hint: nil, before_input: nil, after_input: nil, **options) ⇒ Field
Returns a new instance of Field.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ccs/components/govuk/field.rb', line 48 def initialize(attribute:, form_group: nil, hint: nil, before_input: nil, after_input: nil, **) super(**) (hint[:attributes] ||= {})[:id] = "#{attribute}-hint" if hint && !hint.dig(:attributes, :id) @attribute = attribute @error_message = (attribute) @form_group = FormGroup.new(attribute: attribute, error_message: @error_message, context: @context, **(form_group || {})) @hint = Hint.new(context: @context, **hint) if hint @before_input = before_input @after_input = after_input end |
Instance Method Details
#render {|displayed_error_message| ... } ⇒ ActiveSupport::SafeBuffer
Generates the HTML to wrap arround a GDS form input component
72 73 74 |
# File 'lib/ccs/components/govuk/field.rb', line 72 def render(&) form_group.render(&) end |