Skip to content

Commit

Permalink
extract checked_value and unchecked_value before passing options to t…
Browse files Browse the repository at this point in the history
…he check_box helper so as not to make them attributes of the resulting input HTML element
  • Loading branch information
DerGuteMoritz authored and justinfrench committed Aug 1, 2010
1 parent 19257b2 commit 281ea98
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/formtastic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/inputs/boolean_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 281ea98

Please sign in to comment.