Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix formtastic 1.2 multiple select clearing #799

Closed
wants to merge 1 commit into from

3 participants

@felixbuenemann

This approach is similar to what's needed to clear multiple checkboxes.

@felixbuenemann felixbuenemann Insert hidden field for multiple selects to allow clearing.
This approach is similar to what's needed to clear multiple
checkboxes.
f2d44a9
@felixbuenemann

If someone can get the 1.2 specs to run it would be great to verify this doesn't break anything. Also it would be good to extend the spec to check for the hidden field.

@felixbuenemann

FYI the error I'm getting on about 95% of the specs:
```Failure/Error: form = semantic_form_for(@fred) do |builder|
wrong number of arguments (1 for 0)


I don' really have an idea why. Maybe because of the way the method is build through module_eval in lib/formtastic.rb:1923

I tried running the specs with both ruby-1.8.7 and 1.9.2.
@kchien

@fbuenemann - thanks to @justinfrench, I made sure I was using Rails 2.3.x, and all of the specs pass.
Did you try with Rails 3 or 2.3.x?

@felixbuenemann

Bundler picked up Rails 3.1.3.
Update: OK, specs work and are all passing when using ruby-1.8.7 and export RAILS_2=1

@justinfrench

I think we're at the point where this and #802 are duplicates. Since #802 has tests, let's close this and pick it up there. I've posed one question already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 4, 2012
  1. @felixbuenemann

    Insert hidden field for multiple selects to allow clearing.

    felixbuenemann authored
    This approach is similar to what's needed to clear multiple
    checkboxes.
This page is out of date. Refresh to see the latest.
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.
#
Something went wrong with that request. Please try again.