Class: CCS::Components::GovUK::Field::Input
- Inherits:
-
CCS::Components::GovUK::Field
- Object
- Base
- CCS::Components::GovUK::Field
- CCS::Components::GovUK::Field::Input
- Defined in:
- lib/ccs/components/govuk/field/input.rb,
lib/ccs/components/govuk/field/input/select.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/input/password_input.rb,
lib/ccs/components/govuk/field/input/text_input/fix.rb,
lib/ccs/components/govuk/field/input/character_count.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 Input
This class is used to create a form for an individual field, e.g. text input or select. It will wrap the input in the form group and:
-
display the label
-
display the hint (if there is one)
-
find and display the error message (if there is one)
Direct Known Subclasses
Defined Under Namespace
Classes: CharacterCount, FileUpload, PasswordInput, Select, TextInput, Textarea
Constant Summary
Constants inherited from Base
Instance Method Summary collapse
-
#initialize(attribute:, label:, **options) ⇒ Input
constructor
A new instance of Input.
-
#render { ... } ⇒ ActiveSupport::SafeBuffer
Generates the HTML to wrap arround a GDS form component.
Constructor Details
#initialize(attribute:, label:, **options) ⇒ Input
Returns a new instance of Input.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ccs/components/govuk/field/input.rb', line 33 def initialize(attribute:, label:, **) super(attribute: attribute, **) set_described_by(@options, @attribute, @error_message, [:hint]) @options[:attributes][:class] << " #{self.class::DEFAULT_ATTRIBUTES[:class]}--error" if @error_message field_id = @options.dig(:attributes, :id) (label[:attributes] ||= {})[:for] = field_id if field_id @label = Label.new(attribute: attribute, form: @options[:form], context: @context, **label) end |
Instance Method Details
#render { ... } ⇒ ActiveSupport::SafeBuffer
Generates the HTML to wrap arround a GDS form component
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ccs/components/govuk/field/input.rb', line 52 def render super do || concat(label.render) concat(hint.render) if hint concat() concat(before_input) if before_input concat(yield) concat(after_input) if after_input end end |