Class: ActionView::Helpers::FormBuilder

Inherits:
Object
  • Object
show all
Includes:
SimpleFormWithClientValidation::ActionViewExtensions::Builder
Defined in:
lib/simple_form_with_client_validation/action_view_extensions/builder.rb

Instance Method Summary collapse

Methods included from SimpleFormWithClientValidation::ActionViewExtensions::Builder

#collection_check_boxes, #collection_radio_buttons, #simple_fields_for

Instance Method Details

#collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/simple_form_with_client_validation/action_view_extensions/builder.rb', line 278

def collection_select(attribute, collection, value_method, text_method, options={}, html_options={})
  if value_method.respond_to?(:call) || text_method.respond_to?(:call)
    collection = collection.map do |item|
      value = value_for_collection(item, value_method)
      text  = value_for_collection(item, text_method)

      default_html_options = default_html_options_for_collection(item, value, options, html_options)
      disabled = value if default_html_options[:disabled]
      selected = value if default_html_options[:selected]

      [value, text, selected, disabled]
    end

    [:disabled, :selected].each do |option|
      option_value    = collection.map(&:pop).compact
      options[option] = option_value if option_value.present?
    end
    value_method, text_method = :first, :last
  end

  original_collection_select(attribute, collection, value_method, text_method, options, html_options)
end

#original_collection_selectObject

Override default Rails collection_select helper to handle lambdas/procs in text and value methods, so it works the same way as collection_radio_buttons and collection_check_boxes in SimpleFormWithClientValidation. If none of text/value methods is a callable object, then it just delegates back to original collection select.



277
# File 'lib/simple_form_with_client_validation/action_view_extensions/builder.rb', line 277

alias :original_collection_select :collection_select