Sha256: b6aa7b91e39557b6737d64c22c8ababd4a5603bc49c61d6848bafecf4e954039

Contents?: true

Size: 876 Bytes

Versions: 40

Compression:

Stored size: 876 Bytes

Contents

# frozen_string_literal: true

module EacRailsUtils
  module CommonFormHelper
    class FormBuilder
      module SelectField
        def select_field(field_name, options = {})
          options = options.dup
          field(field_name, options) do
            form.select(field_name, select_options(field_name, options),
                        options, options[:html] || {})
          end
        end

        private

        def select_options(field_name, options)
          options[:options] || listable_select_options(field_name) || raise('No options found')
        end

        def listable_select_options(field_name)
          return nil unless model_instance.class.respond_to?(:lists)
          return nil unless model_instance.class.lists.respond_to?(field_name)

          model_instance.class.lists.send(field_name).options
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
eac_rails_utils-0.25.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.24.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.23.4 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.23.3 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.23.2 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.23.1 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.23.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.22.3 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.22.2 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.22.1 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.22.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.21.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.20.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.19.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.18.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.17.2 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.17.1 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.17.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.16.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.15.2 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb