Class: CCS::Components::GovUK::Field::Inputs::Checkboxes
- Inherits:
-
CCS::Components::GovUK::Field::Inputs
- Object
- Base
- CCS::Components::GovUK::Field
- CCS::Components::GovUK::Field::Inputs
- CCS::Components::GovUK::Field::Inputs::Checkboxes
- Defined in:
- lib/ccs/components/govuk/field/inputs/checkboxes.rb
Overview
GOV.UK Checkboxes
This is used for generating the checkboxes component from the GDS - Components - Checkboxes
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
The default attributes for the checkboxes
{ class: 'govuk-checkboxes', data: { module: 'govuk-checkboxes' } }.freeze
Instance Method Summary collapse
-
#initialize(attribute:, checkbox_items:, **options) ⇒ Checkboxes
constructor
A new instance of Checkboxes.
Methods inherited from CCS::Components::GovUK::Field::Inputs
Methods inherited from CCS::Components::GovUK::Field
Constructor Details
#initialize(attribute:, checkbox_items:, **options) ⇒ Checkboxes
Returns a new instance of Checkboxes.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ccs/components/govuk/field/inputs/checkboxes.rb', line 25 def initialize(attribute:, checkbox_items:, **) super(attribute: attribute, **) @options[:values] ||= [] @options[:values] = (@options[:model] || @options[:form].object).send(attribute) || [] if @options[:model] || @options[:form] checkbox_items.each { |checkbox_item| checkbox_item[:checked] = @options[:values].include?(checkbox_item[:value]) } if @options[:values].any? checkbox_items.each { |checkbox_item| set_described_by(checkbox_item, @attribute, @error_message, @hint&.send(:options)) } unless @fieldset checkbox_item_class = @options[:form] ? Item::Checkbox::Form : Inputs::Item::Checkbox::Tag @input_items = checkbox_items.map { |checkbox_item| checkbox_item[:divider] ? Item::Divider.new(divider: checkbox_item[:divider], type: 'checkboxes') : checkbox_item_class.new(attribute: attribute, form: @options[:form], context: @context, **checkbox_item) } end |