Skip to content
This repository
Browse code

Insert hidden field for multiple selects to allow clearing.

This approach is similar to what's needed to clear multiple
checkboxes.
  • Loading branch information...
commit 23e7f61baeae49018154faa3256d052697061b1d 1 parent 2bf6014
Felix Bünemann felixbuenemann authored kchien committed

Showing 1 changed file with 10 additions and 0 deletions. Show diff stats Hide diff stats

  1. +10 0 lib/formtastic.rb
10 lib/formtastic.rb
@@ -843,11 +843,21 @@ def select_input(method, options)
843 843 select(input_name, collection, strip_formtastic_options(options), html_options)
844 844 end
845 845
  846 + if html_options[:multiple]
  847 + select_html << create_hidden_field_for_multiple_select(input_name)
  848 + end
  849 +
846 850 label_options = options_for_label(options).merge(:input_name => input_name)
847 851 label_options[:for] ||= html_options[:id]
848 852 label(method, label_options) << select_html
849 853 end
850 854
  855 + # Outputs a custom hidden field for multiple selects
  856 + def create_hidden_field_for_multiple_select(method) #:nodoc:
  857 + input_name = "#{object_name}[#{method.to_s}][]"
  858 + template.hidden_field_tag(input_name, '')
  859 + end
  860 +
851 861 # Outputs a timezone select input as Rails' time_zone_select helper. You
852 862 # can give priority zones as option.
853 863 #

0 comments on commit 23e7f61

Please sign in to comment.
Something went wrong with that request. Please try again.