You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, when requesting the edit form above, simple_form will list all possible roles that a user can have, checking the onces where a UserRole record exists for the @user object.
But if I add the :checked => [...] option to the f.association call with an array of role id's, I would expect simple_form to pre-check those roles and those roles only. What I get instead, is a set of check boxes with both the existing roles checked + the roles given in the :checked array (i.e. it has merged the @user.user_roles array with the :checked array).
I see the same issue when using f.collection_check_boxes :role_ids, Role.all, :id, :name, :checked => [...] instead of f.association ....
I would expect the array given to :checked to override any existing associations on the @user object. Otherwise simple_form will re-check un-checked check boxes on form validation errors.
The text was updated successfully, but these errors were encountered:
I tried to reproduce this issue and I saw that this is the default behavior of check_box rails helper. I have not figured out how to fix this issue. Any clues @carlosantoniodasilva?
Hey guys, sorry to delay that much to answer you here.
It really seems to be more a Rails issue than a SimpleForm one, we will try to check what Rails and SimpleForm are doing to see if we can find out what's going on here. Thanks.
nashby
pushed a commit
to nashby/simple_form
that referenced
this issue
Dec 2, 2011
Consider a User who can have many Roles:
One can make a view where a user can be edited and roles can be selected:
By default, when requesting the edit form above, simple_form will list all possible roles that a user can have, checking the onces where a
UserRole
record exists for the@user
object.But if I add the
:checked => [...]
option to thef.association
call with an array of role id's, I would expect simple_form to pre-check those roles and those roles only. What I get instead, is a set of check boxes with both the existing roles checked + the roles given in the:checked
array (i.e. it has merged the@user.user_roles
array with the:checked
array).I see the same issue when using
f.collection_check_boxes :role_ids, Role.all, :id, :name, :checked => [...]
instead off.association ...
.I would expect the array given to
:checked
to override any existing associations on the@user
object. Otherwise simple_form will re-check un-checked check boxes on form validation errors.The text was updated successfully, but these errors were encountered: