Why does simple_form generate input tags twice for boolean fields (one is hidden and the other is not)?
In my simple_form, I have this:
<%= form.input :over_phone, as: :boolean, input_html: {checked: true} %>
which generates this:
<div class="control-group boolean optional order_over_phone"> <label class="boolean optional control-label" for="order_over_phone">Order over phone</label> <div class="controls"> <input name="order[over_phone]" type="hidden" value="0"> <label class="checkbox"> <input checked="checked" class="boolean optional" id="order_over_phone" name="order[over_phone]" type="checkbox" value="1"> </label> </div> </div>
As you can see, one input tag is hidden with a value of 0, and the other is invisible with a value of 1. If I submit a form, in the message parameters I get both values:
order[over_phone]:0 order[over_phone]:1
I have a random behavior when creating a model associated with this Boolean field, so I wonder if this is caused by simple_form. This does not happen with non-boolean field types.
If you encounter a similar problem, please share your experience.
I am using simple_form 2.1.0.
ruby-on-rails simple-form form-helpers
Nurbo
source share