Class: ActionView::Helpers::FormBuilder
- Inherits:
-
Object
- Object
- ActionView::Helpers::FormBuilder
- Defined in:
- lib/simple_form_with_client_validation/action_view_extensions/builder.rb
Direct Known Subclasses
Instance Method Summary collapse
- #collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
-
#original_collection_select ⇒ Object
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.
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, ={}, ={}) 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) = (item, value, , ) disabled = value if [:disabled] selected = value if [:selected] [value, text, selected, disabled] end [:disabled, :selected].each do |option| option_value = collection.map(&:pop).compact [option] = option_value if option_value.present? end value_method, text_method = :first, :last end original_collection_select(attribute, collection, value_method, text_method, , ) end |
#original_collection_select ⇒ Object
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 |