formtastic - multiple forms with check boxes leads to double used html id

on under asbach
1 minute read

Out Of Date Warning

This article was published on 10/12/2011, this means the content may be out of date or no longer relevant.
You should verify that the technical information in this article is still up to date before relying upon it for your own purposes.

Problem: When creating muliple, similar structured forms with formtastic and using check boxes, then all the forms seems to be correlated: Checking a check_box of the check_boxes in one form, changes them in another, too. This is because they all used the same id for the check box input. One can change this, by using the option index => object.id in the semantic form for:

semantic_form_for user, :index => user.id do |f|
 ....
  f.input :options, :as => :check_boxes
end

In this way, the checkboxes get a prefix of the given index. This option seems to be undocument, but can be found in the source code choice_input_dom_id.


Reposted from notes.it-jobs-und-stellen.de