Sha256: 3477344ef9a7540465c553a83392b062e81e725b8f49d5779815c4d003471b1b

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

module GOVUKDesignSystemFormBuilder
  module Elements
    module CheckBoxes
      class CollectionCheckBox < GOVUKDesignSystemFormBuilder::Base
        def initialize(builder, object_name, attribute_name, checkbox, hint_method = nil, link_errors: false)
          super(builder, object_name, attribute_name)
          @checkbox  = checkbox
          @item      = checkbox.object
          @value     = checkbox.value
          @hint_text = @item.send(hint_method) if hint_method.present?
          @link_errors = link_errors
        end

        def html
          @builder.content_tag('div', class: 'govuk-checkboxes__item') do
            @builder.safe_join(
              [
                @checkbox.check_box(
                  id: field_id(link_errors: @link_errors),
                  class: "govuk-checkboxes__input",
                  aria: { describedby: hint_id }
                ),
                label_element.html,
                hint_element.html
              ]
            )
          end
        end

      private

        def label_element
          @label_element ||= Label.new(@checkbox, @object_name, @attribute_name, value: @value)
        end

        def hint_element
          @hint_element ||= Hint.new(@builder, @object_name, @attribute_name, @hint_text, value: @value)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
govuk_design_system_formbuilder-0.9.4 lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb
govuk_design_system_formbuilder-0.9.3 lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb