Allow disabling error markup generation on a per-field basis #46666
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a replacement for #46618
Motivation / Background
I'm working on a forms framework on the Primer team at GitHub that allows rendering forms declaratively. My pair and I noticed today that Rails will wrap invalid inputs and labels with a
<div>
containing a class offield_with_errors
, ostensibly allowing for custom styling of invalid fields. We also learned this behavior can be customized by setting the application-levelActionView::Base.field_error_proc
option.Our framework automatically handles styling invalid fields in accordance with our design system. The additional wrapper
<div>
, while something we can work around, unexpectedly led to a visual regression today in our testing:As you can see, the little arrows on the right-hand side of the select list are outside the red outline. The arrows are implemented as an
:after
selector and live here. The additional<div>
causes the:after
selector to place the mask after the<div>
instead of after the<select>
.Detail
My pair and I were unable to find any field-level option to disable wrapping, so I have submitted this PR. You can now pass
generate_error_markup: false
to form helpers to skip wrapping fields with the aforementioned<div>
:Open Questions
generate_error_markup:
option can be passed to all form helpers and form builder methods, I'm not sure where the most appropriate place is to document the changes. Is someone able to help me with that?Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]