I am using check_box_tag in a form helper and all the other fields preserve their inputs after a submit validation error, but check_box_tag does not. Is there some way to get check_box_tag to save its state on a failed form submit? Here's the code:
<%= check_box_tag 'user_ids[]',
user.id,
false,
:class => 'user_checkbox' %>
I need to use check_box_tag instead of check_box in this context.
You're passing false
to check_box_tag
so all checkboxes are disabled. To fix that you can do smth like:
<%= check_box_tag 'user_ids[]',
user.id,
params[:user_ids].include?(user.id),
:class => 'user_checkbox' %>
It checks whether user.id
was among user ids that were submitted and if it was then checkbox is checked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With