Permalink
Browse files

added possibility to check check boxes via input_html options

  • Loading branch information...
1 parent c5e311a commit fd3a628859b1b262f1c3217dc7a9a1831a8bf431 @yuszuv committed Jan 12, 2013
Showing with 19 additions and 1 deletion.
  1. +3 −1 lib/formtastic/inputs/boolean_input.rb
  2. +16 −0 spec/inputs/boolean_input_spec.rb
@@ -101,7 +101,9 @@ def input_html_options_name
end
def checked?
- if defined? ActionView::Helpers::InstanceTag
+ if input_html_options.key?(:checked)
+ input_html_options[:checked]
+ elsif defined? ActionView::Helpers::InstanceTag
object && ActionView::Helpers::InstanceTag.check_box_checked?(object.send(method), checked_value)
else
object && boolean_checked?(object.send(method), checked_value)
@@ -41,6 +41,22 @@
output_buffer.should have_tag('form li label input[@type="checkbox"][@value="1"]')
end
+ it 'should generate a checked input if :input_html => { :checked => true } is passed' do
+ @output_buffer = ''
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:answer_comments, :as => :boolean, :input_html => {:checked => true}))
+ end)
+ output_buffer.should have_tag('form li label input[@checked="checked"]')
+ end
+
+ it 'should not generate a checked input if :input_html => { :checked => false } is passed' do
+ @output_buffer = ''
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:answer_comments, :as => :boolean, :input_html => {:checked => false}))
+ end)
+ output_buffer.should_not have_tag('form li label input[@checked="checked"]')
+ end
+
it 'should generate a checked input if object.method returns true' do
output_buffer.should have_tag('form li label input[@checked="checked"]')
output_buffer.should have_tag('form li input[@name="post[allow_comments]"]', :count => 2)

0 comments on commit fd3a628

Please sign in to comment.