Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 038dc3ab3966692bf866944af3e1ef2dd9eee246 1 parent 19257b2
Moritz Heidkamp authored

Showing 2 changed files with 4 additions and 2 deletions. Show diff stats Hide diff stats

  1. +3 1 lib/formtastic.rb
  2. +1 1  spec/inputs/boolean_input_spec.rb
4 lib/formtastic.rb
@@ -1205,9 +1205,11 @@ def boolean_input(method, options)
1205 1205 html_options = options.delete(:input_html) || {}
1206 1206 checked = options.key?(:checked) ? options[:checked] : options[:selected]
1207 1207 html_options[:checked] = checked == true if [:selected, :checked].any? { |k| options.key?(k) }
  1208 + checked_value = options.delete(:checked_value) || '1'
  1209 + unchecked_value = options.delete(:unchecked_value) || '0'
1208 1210
1209 1211 input = self.check_box(method, strip_formtastic_options(options).merge(html_options),
1210   - options.delete(:checked_value) || '1', options.delete(:unchecked_value) || '0')
  1212 + checked_value, unchecked_value)
1211 1213 options = options_for_label(options)
1212 1214
1213 1215 # the label() method will insert this nested input into the label at the last minute
2  spec/inputs/boolean_input_spec.rb
@@ -38,7 +38,7 @@
38 38 concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
39 39 end
40 40
41   - output_buffer.should have_tag('form li label input[@type="checkbox"][@value="checked"]')
  41 + output_buffer.should have_tag('form li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
42 42 output_buffer.should have_tag('form li label input[@type="hidden"][@value="unchecked"]')
43 43 end
44 44

0 comments on commit 038dc3a

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