Sha256: 51a83dc38aff02866257d69b0e4abd9288c0fda1165cd5e16ff37e4bc56aace7

Contents?: true

Size: 1.6 KB

Versions: 16

Compression:

Stored size: 1.6 KB

Contents

module GOVUKDesignSystemFormBuilder
  module Containers
    class CheckBoxesFieldset < Base
      include Traits::Error
      include Traits::Hint

      def initialize(builder, object_name, attribute_name, hint:, legend:, caption:, small:, classes:, form_group:, multiple:, &block)
        super(builder, object_name, attribute_name, &block)

        @legend        = legend
        @caption       = caption
        @hint          = hint
        @small         = small
        @classes       = classes
        @form_group    = form_group
        @multiple      = multiple
        @block_content = capture { block.call }
      end

      def html
        Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
          Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
            safe_join([hint_element, error_element, hidden_field, checkboxes])
          end
        end
      end

    private

      def hidden_field
        return unless @multiple

        @builder.hidden_field(@attribute_name, value: "", name: hidden_field_name)
      end

      def hidden_field_name
        format("%<object_name>s[%<attribute_name>s][]", object_name: @object_name, attribute_name: @attribute_name)
      end

      def fieldset_options
        {
          legend: @legend,
          caption: @caption,
          described_by: [error_element.error_id, hint_element.hint_id]
        }
      end

      def checkboxes
        Containers::CheckBoxes.new(@builder, small: @small, classes: @classes).html do
          @block_content
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
govuk_design_system_formbuilder-2.3.0b1 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.2.0 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.1.9 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.1.8 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.1.7 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.1.7b2 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.1.7b1 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.1.6 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.1.5 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.1.4 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.1.3 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.1.2 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.1.1 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.1.0 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.0.0 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
govuk_design_system_formbuilder-2.0.0b4 lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb