lib/ccs/components/govuk/field/inputs/radios.rb in ccs-frontend_helpers-0.1.2 vs lib/ccs/components/govuk/field/inputs/radios.rb in ccs-frontend_helpers-0.2.0

- old
+ new

@@ -21,31 +21,30 @@ attr_reader :radio_items public - # rubocop:disable Metrics/CyclomaticComplexity + # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity # @param (see CCS::Components::GovUK::Field::Inputs#initialize) # @param radio_items [Array<Hash>] an array of options for the radios. # See {Components::GovUK::Field::Inputs::Item::Radio#initialize Radio#initialize} for details of the items in the array. # # @option (see CCS::Components::GovUK::Field::Inputs#initialize) def initialize(attribute:, radio_items:, **options) super(attribute: attribute, **options) - if @options[:model] || @options[:form] - value = (@options[:model] || @options[:form].object).send(attribute) - radio_items.each { |radio_item| radio_item[:checked] = value == radio_item[:value] } - end + @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 @radio_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 - # rubocop:enable Metrics/CyclomaticComplexity + # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity # Generates the HTML for the GOV.UK Radios component # # @return [ActiveSupport::SafeBuffer]