Sha256: 1e394bbaa7cc471b26acba4e40cec01c95965335a1d5ea126fcda583c45c855b

Contents?: true

Size: 1.37 KB

Versions: 10

Compression:

Stored size: 1.37 KB

Contents

require_relative '../checkbox'

module CCS
  module Components
    module GovUK
      class Field < Base
        class Inputs < Field
          class Item < Base
            class Checkbox < Item
              # = GOV.UK Field Inputs Checkbox tag
              #
              # This is used to generate an individual checkbox item using +check_box_tag+

              class Tag < Checkbox
                # @param (see CCS::Components::GovUK::Field::Items::Item::Checkbox#initialize)
                #
                # @option (see CCS::Components::GovUK::Field::Items::Item::Checkbox#initialize)

                def initialize(attribute:, label:, **options)
                  super(attribute: attribute, label: label, **options)

                  @options[:attributes][:id] ||= "#{sanitize_to_id(@attribute)}_#{sanitize_to_id(@value)}"

                  @label = Label.new(attribute: @options[:attributes][:id], context: @context, **label)
                end

                # Generates the HTML for the checkbox input
                #
                # @return [ActiveSupport::SafeBuffer]

                def render
                  super() do
                    context.check_box_tag("#{@attribute}[]", @value, @options[:checked], **@options[:attributes])
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ccs-frontend_helpers-0.3.0 lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb
ccs-frontend_helpers-0.2.0 lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb
ccs-frontend_helpers-0.1.2 lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb
ccs-frontend_helpers-0.1.1 lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb
ccs-frontend_helpers-0.1.1.rc.1 lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb
ccs-frontend_helpers-0.1.0.rc.7 lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb
ccs-frontend_helpers-0.1.0.rc.6 lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb
ccs-frontend_helpers-0.1.0.rc.5 lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb
ccs-frontend_helpers-0.1.0.rc.4 lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb
ccs-frontend_helpers-0.1.0.rc.3 lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb