Skip to content
Browse files

extract checked_value and unchecked_value before passing options to t…

…he check_box helper so as not to make them attributes of the resulting input HTML element
  • Loading branch information...
1 parent 19257b2 commit 038dc3ab3966692bf866944af3e1ef2dd9eee246 @DerGuteMoritz committed Aug 1, 2010
Showing with 4 additions and 2 deletions.
  1. +3 −1 lib/formtastic.rb
  2. +1 −1 spec/inputs/boolean_input_spec.rb
View
4 lib/formtastic.rb
@@ -1205,9 +1205,11 @@ def boolean_input(method, options)
html_options = options.delete(:input_html) || {}
checked = options.key?(:checked) ? options[:checked] : options[:selected]
html_options[:checked] = checked == true if [:selected, :checked].any? { |k| options.key?(k) }
+ checked_value = options.delete(:checked_value) || '1'
+ unchecked_value = options.delete(:unchecked_value) || '0'
input = self.check_box(method, strip_formtastic_options(options).merge(html_options),
- options.delete(:checked_value) || '1', options.delete(:unchecked_value) || '0')
+ checked_value, unchecked_value)
options = options_for_label(options)
# the label() method will insert this nested input into the label at the last minute
View
2 spec/inputs/boolean_input_spec.rb
@@ -38,7 +38,7 @@
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
end
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="checked"]')
+ output_buffer.should have_tag('form li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
output_buffer.should have_tag('form li label input[@type="hidden"][@value="unchecked"]')
end

0 comments on commit 038dc3a

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