Permalink
Browse files

Insert hidden field for multiple selects to allow clearing.

This approach is similar to what's needed to clear multiple
checkboxes.
  • Loading branch information...
1 parent 2bf6014 commit 23e7f61baeae49018154faa3256d052697061b1d @felixbuenemann felixbuenemann committed with kchien Jan 4, 2012
Showing with 10 additions and 0 deletions.
  1. +10 −0 lib/formtastic.rb
View
10 lib/formtastic.rb
@@ -843,11 +843,21 @@ def select_input(method, options)
select(input_name, collection, strip_formtastic_options(options), html_options)
end
+ if html_options[:multiple]
+ select_html << create_hidden_field_for_multiple_select(input_name)
+ end
+
label_options = options_for_label(options).merge(:input_name => input_name)
label_options[:for] ||= html_options[:id]
label(method, label_options) << select_html
end
+ # Outputs a custom hidden field for multiple selects
+ def create_hidden_field_for_multiple_select(method) #:nodoc:
+ input_name = "#{object_name}[#{method.to_s}][]"
+ template.hidden_field_tag(input_name, '')
+ end
+
# Outputs a timezone select input as Rails' time_zone_select helper. You
# can give priority zones as option.
#

0 comments on commit 23e7f61

Please sign in to comment.