formtastic: :hidden_fields => false should not render "none" for checkboxes

When :as => :chck_boxes, :hidden_fields => false, the hidden “_none” field is still rendered.

PROBLEM: fantom, fake entry in the resulting array.

Let me better give an example:

= semantic_form_for @property_search do |f|
  = f.inputs do
    = f.input :bedrooms, :as => :check_boxes, :hidden_fields => false, :collection => {0 => "Studio", 1 => "1 Bedder", 2 => "2 Beds"}
  f.buttons

This renders (stripped to bare):

<input id="property_search_bedrooms_none" name="property_search[bedrooms][]" type="hidden" value="">
<input id="property_search_bedrooms_0" name="property_search[bedrooms][]" type="checkbox" value="0">
<input id="property_search_bedrooms_1" name="property_search[bedrooms][]" type="checkbox" value="1">
<input id="property_search_bedrooms_2" name="property_search[bedrooms][]" type="checkbox" value="2">

The data that gets into into params[:property_search] depending on what’s checked:

  • Nothing checked: {"bedrooms"=>[""]}
  • 1 item is checked: {"bedrooms"=>["", "0"]}
  • 2 items are checked: {"bedrooms"=>["", "0", "1"]} etc

So my suggestion is NOT to render any hidden fields when the option is specified to avoid a fake empty element in the array.

About this issue

  • Original URL
  • State: closed
  • Created 13 years ago
  • Comments: 15 (14 by maintainers)

Most upvoted comments

Closing. Changing the behaviour we have will cause non-obvious problems for many existing apps, and there’s no obviously right or wrong approach. Rails 4 has introduced some hidden inputs in places too (like for a multi-select), so that’s more reason to stick with what we have.