Class: CCS::Components::GovUK::Field::Inputs::Radios
- Inherits:
-
CCS::Components::GovUK::Field::Inputs
- Object
- Base
- CCS::Components::GovUK::Field
- CCS::Components::GovUK::Field::Inputs
- CCS::Components::GovUK::Field::Inputs::Radios
- Defined in:
- lib/ccs/components/govuk/field/inputs/radios.rb
Overview
GOV.UK Radios
This is used for generating the radios component from the GDS - Components - Radios
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
The default attributes for the radios
{ class: 'govuk-radios', data: { module: 'govuk-radios' } }.freeze
Instance Method Summary collapse
-
#initialize(attribute:, radio_items:, **options) ⇒ Radios
constructor
A new instance of Radios.
Methods inherited from CCS::Components::GovUK::Field::Inputs
Methods inherited from CCS::Components::GovUK::Field
Constructor Details
#initialize(attribute:, radio_items:, **options) ⇒ Radios
Returns a new instance of Radios.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ccs/components/govuk/field/inputs/radios.rb', line 31 def initialize(attribute:, radio_items:, **) super(attribute: attribute, **) @options[:value] = (@options[:model] || @options[:form].object).send(attribute) if @options[:model] || @options[:form] radio_items.each { |radio_item| radio_item[:checked] = @options[:value] == radio_item[:value] } if @options[:value] radio_item_class = @options[:form] ? Item::Radio::Form : Inputs::Item::Radio::Tag @input_items = radio_items.map { |radio_item| radio_item[:divider] ? Item::Divider.new(divider: radio_item[:divider], type: 'radios') : radio_item_class.new(attribute: attribute, form: @options[:form], context: @context, **radio_item) } end |