Skip to content

Commit

Permalink
Merge pull request #1219 from sandfoxme/1218-checkboxes-control-is-br…
Browse files Browse the repository at this point in the history
…oken

Check boxes control is not saved as empty array if no boxes were checked (master)

closes #1218
  • Loading branch information
mikz committed May 25, 2016
2 parents f230190 + 4cf554d commit eed48bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions lib/formtastic/inputs/check_boxes_input.rb
Expand Up @@ -99,17 +99,17 @@ def choice_html(choice)
end

def hidden_field_for_all
if hidden_fields?
if hidden_fields_for_every?
''
else
options = {}
options[:class] = [method.to_s.singularize, 'default'].join('_') if value_as_class?
options[:id] = [object_name, method, 'none'].join('_')
template.hidden_field_tag(input_name, '', options)
else
''
end
end

def hidden_fields?
def hidden_fields_for_every?
options[:hidden_fields]
end

Expand Down Expand Up @@ -170,7 +170,7 @@ def input_name
protected

def checkbox_input(choice)
if hidden_fields?
if hidden_fields_for_every?
check_box_with_hidden_input(choice)
else
check_box_without_hidden_input(choice)
Expand Down
12 changes: 6 additions & 6 deletions spec/inputs/check_boxes_input_spec.rb
Expand Up @@ -56,8 +56,8 @@
expect(output_buffer).not_to have_tag("form li fieldset ol li input[@type='hidden']")
end

it 'should not render hidden input for each choice outside the ol' do
expect(output_buffer).not_to have_tag("form li fieldset > input[@type='hidden']")
it 'should render one hidden input for each choice outside the ol' do
expect(output_buffer).to have_tag("form li fieldset > input[@type='hidden']", :count => 1)
end

describe "each choice" do
Expand Down Expand Up @@ -90,12 +90,12 @@
end
end

it 'should not have a hidden field with an empty array value for the collection to allow clearing of all checkboxes' do
expect(output_buffer).not_to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value='']")
it 'should have a hidden field with an empty array value for the collection to allow clearing of all checkboxes' do
expect(output_buffer).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
end

it 'should not have a hidden field with an empty array value followed by the ol' do
expect(output_buffer).not_to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value=''] + ol")
it 'the hidden field with an empty array value should be followed by the ol' do
expect(output_buffer).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value=''] + ol", :count => 1)
end

it 'should not have a hidden field with an empty string value for the collection' do
Expand Down

0 comments on commit eed48bf

Please sign in to comment.