Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Added possibility to manually decide whether a check box is checked #909

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+19 −1
Split
@@ -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)