Sha256: 0c5c418e4dacefce6b78780b6bf381ec0fef19f545c2b2da5d8f850c7bad67cb

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 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
          content_tag('div', class: 'govuk-checkboxes__item') do
            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(@builder, @object_name, @attribute_name, @checkbox, value: @value, link_errors: @link_errors)
        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

3 entries across 3 versions & 1 rubygems

Version Path
govuk_design_system_formbuilder-1.0.1 lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb
govuk_design_system_formbuilder-1.0.0 lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb
govuk_design_system_formbuilder-0.9.8 lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb