mercredi 4 mai 2016

Rails 4 collection_check_boxes persistent after form refresh

I'm using Rails 4 collection_check_boxes in my forms. Filling out the form, I check some of the checkboxes. I've noticed that when the form refreshes after validation error, the checkboxes that were checked persists. Is this a feature of the tag? I couldn't find this information in the docs.

Checkbox form field code:

<div class="field">
  <%= f.label "Area of Interest" %><br />
  <%= f.collection_check_boxes :interest_ids, Interest.all, :id, :name do |b| %>
    <div class="collection-check-box">
      <%= b.check_box %>
      <%= b.label %>
    </div>
  <% end %>
</div>

I do want the checkboxes to stay checked after form refresh but wanted to make sure it is a feature and not just a coincidence that is it working for me.

Any information would be helpful, thanks!

Aucun commentaire:

Enregistrer un commentaire