Class: CCS::Components::GovUK::Field::Inputs::Item::Checkbox::Form

Inherits:
CCS::Components::GovUK::Field::Inputs::Item::Checkbox show all
Defined in:
lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb

Overview

GOV.UK Field Inputs Checkbox form tag

This is used to generate an individual checkbox item using form.check_box

Constant Summary

Constants inherited from CCS::Components::GovUK::Field::Inputs::Item::Checkbox

DEFAULT_ATTRIBUTES, ITEM_TYPE

Constants inherited from Base

Base::DEFAULT_ATTRIBUTES

Instance Method Summary collapse

Constructor Details

#initialize(attribute:, label:, **options) ⇒ Form

Returns a new instance of Form.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb', line 19

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

  (label[:attributes] ||= {})[:value] = @value
  label[:attributes][:for] = @options[:attributes][:id] if @options[:attributes][:id]

  @options[:attributes][:multiple] = true
  @options[:attributes][:include_hidden] = false

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

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the checkbox input

Returns:

  • (ActiveSupport::SafeBuffer)


35
36
37
38
39
# File 'lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb', line 35

def render
  super do
    @options[:form].check_box(@attribute, @options[:attributes], @value)
  end
end