Sha256: cdf23d197c0e14e748fda84b96b7454bf4dd060db3d5c89108be10b90eee8018

Contents?: true

Size: 1.36 KB

Versions: 33

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module EacRailsUtils
  module CommonFormHelper
    class FormBuilder
      module RadioSelectField
        def radio_select_field(field_name, radios_values, options = {})
          field(field_name, options) do
            radios(field_name, radios_values)
          end
        end

        private

        def radios(field_name, radios_values)
          b = ActiveSupport::SafeBuffer.new
          radios_values.each do |r|
            b << radio(field_name, r[0], r[1])
          end
          b
        end

        def radio(field_name, value, label)
          helper.content_tag(:div, class: 'radio') do
            helper.content_tag(:label) do
              form.radio_button(field_name, value) << label
            end
          end
        end

        def extract_select_options(options)
          options.extract!(:prompt, :include_blank)
        end

        def extract_association_key(field_name, options, key, method)
          return options.delete(key) if options.key?(key)
          if model_instance.class.respond_to?(:reflect_on_association)
            return model_instance.class.reflect_on_association(field_name).send(method)
          end

          raise "#{model_instance.class} não possui um método \"reflect_on_association\". " \
            "Defina explicitamente a opção :#{key}"
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
eac_rails_utils-0.22.2 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.22.1 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.22.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.21.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.20.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.19.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.18.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.17.2 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.17.1 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.17.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.16.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.15.2 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.15.1 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.15.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.14.1 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.14.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.13.5 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.13.4 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.13.3 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.13.2 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb