Class: CCS::Components::GovUK::Field::Input::TextInput
- Inherits:
-
CCS::Components::GovUK::Field::Input
- Object
- Base
- CCS::Components::GovUK::Field
- CCS::Components::GovUK::Field::Input
- CCS::Components::GovUK::Field::Input::TextInput
- Defined in:
- lib/ccs/components/govuk/field/input/text_input.rb,
lib/ccs/components/govuk/field/input/text_input/fix.rb
Overview
GOV.UK Input
This is used for generating the input component from the GDS - Components - Text Input
Defined Under Namespace
Classes: Fix
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
The default attributes for the text input
{ class: 'govuk-input' }.freeze
Instance Method Summary collapse
-
#initialize(attribute:, field_type: :text, value: nil, prefix: nil, suffix: nil, input_wrapper: {}, **options) ⇒ TextInput
constructor
A new instance of TextInput.
-
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Text Input component.
Constructor Details
#initialize(attribute:, field_type: :text, value: nil, prefix: nil, suffix: nil, input_wrapper: {}, **options) ⇒ TextInput
Returns a new instance of TextInput.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ccs/components/govuk/field/input/text_input.rb', line 45 def initialize(attribute:, field_type: :text, value: nil, prefix: nil, suffix: nil, input_wrapper: {}, **) super(attribute: attribute, **) @field_type = :"#{field_type}_field" @value = @options[:model] ? @options[:model].send(attribute) : value @prefix = Fix.new(fix: 'pre', context: @context, **prefix) if prefix @suffix = Fix.new(fix: 'suf', context: @context, **suffix) if suffix @input_wrapper_html_options = { class: "govuk-input__wrapper #{input_wrapper[:classes]}".rstrip }.merge(input_wrapper[:attributes] || {}) end |
Instance Method Details
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Text Input component
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ccs/components/govuk/field/input/text_input.rb', line 64 def render form_group.render do || concat(label.render) concat(hint.render) if hint concat() concat(text_input_wrapper do if [:form] [:form].send(field_type, attribute, **[:attributes]) else context.send("#{field_type}_tag", attribute, value, **[:attributes]) end end) end end |