0

I'm having a checkbox which is only used to display an optional input field with JS. When submitting the form, but the value of this field fails validation, it displays the error message but not the field (because of the reload). So I would need to click the checkbox again, to actually show the field. Is there any way how I can preserve the checkbox checked after submitting the form and failing.

Thanks

1 Answer 1

1

Of course implementation can be different from how you implement the form, but general solution is to pass conditions to the checkbox checked attribute

= check_box_tag "show_hidden_field", nil, f.object.errors[:field_name].present?
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.