Class: GOVUKDesignSystemFormBuilder::Elements::TextArea

Inherits:
Base
  • Object
show all
Includes:
Traits::Error, Traits::Hint, Traits::Label, Traits::Supplemental
Defined in:
lib/govuk_design_system_formbuilder/elements/text_area.rb

Instance Method Summary collapse

Methods included from Traits::Supplemental

#supplemental_id

Methods included from Traits::Hint

#hint_id

Methods included from Traits::Error

#error_id

Constructor Details

#initialize(builder, object_name, attribute_name, hint_text:, label:, rows:, max_words:, max_chars:, threshold:, **extra_args, &block) ⇒ TextArea

Returns a new instance of TextArea.


9
10
11
12
13
14
15
16
17
18
19
# File 'lib/govuk_design_system_formbuilder/elements/text_area.rb', line 9

def initialize(builder, object_name, attribute_name, hint_text:, label:, rows:, max_words:, max_chars:, threshold:, **extra_args, &block)
  super(builder, object_name, attribute_name, &block)

  @label      = label
  @hint_text  = hint_text
  @extra_args = extra_args
  @max_words  = max_words
  @max_chars  = max_chars
  @threshold  = threshold
  @rows       = rows
end

Instance Method Details

#htmlObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/govuk_design_system_formbuilder/elements/text_area.rb', line 21

def html
  Containers::CharacterCount.new(@builder, max_words: @max_words, max_chars: @max_chars, threshold: @threshold).html do
    Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
      safe_join(
        [
          [label_element, hint_element, error_element, supplemental_content].map(&:html),
          @builder.text_area(
            @attribute_name,
            id: field_id(link_errors: true),
            class: govuk_textarea_classes,
            aria: {
              describedby: described_by(hint_id, error_id, supplemental_id, limit_description_id)
            },
            **@extra_args.merge(rows: @rows)
          ),
          limit_description
        ].flatten.compact
      )
    end
  end
end