Closed acoffman closed 8 months ago
Most fields like text_fields
are automatically wrapped in a form_group
(which creates the wrapper div, label and errors) by the Trestle form builder. check_box
fields are a special case where they aren't automatically wrapped (primarily due to there being a redundant label by default, and misaligned fields if the label is dropped).
To restore the error fields, wrap the check_box
in a form_group
, optionally specifying label: false
or an alternate label (e.g. 'Deprecation Options').
form_group :deprecated, label: false do
check_box :deprecated
end
Thanks so much, I figured I was just missing something straightforward like that!
As an example, I have the following validation set up in my model:
deprecated
is a boolean field on the ActiveRecord model.I have the following in my form:
If I check the box, the validation runs as expected, attaches the error, and the save fails, but the error message is not displayed on the form field. Just the generic flash "please correct the errors below" banner.
I also have
in the same form. If I change the validation to attach the error to
name
instead:it correctly appears next to the name
input
.Is there something specific I need to do to have the
check_box
helper display validation errors as expected?