Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added possibility to check check boxes via input_html options

  • Loading branch information...
commit fd3a628859b1b262f1c3217dc7a9a1831a8bf431 1 parent c5e311a
@yuszuv authored
View
4 lib/formtastic/inputs/boolean_input.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)
View
16 spec/inputs/boolean_input_spec.rb
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.