[feature request] Merge custom html_options to input elements with errors

Hey Rails-Core,

It started with this Idea after fixing a bug I found with field_with_errors [1]:

Instead of wrap an invalid input with

[…]
easy add a custom css

class (or data-attr.) to the input element itself.

like:

Which is required by some frontend frameworks or if the project

requirements don’t allow extra markup around inputs with errors.

After a research, field_error_proc looked promising but required parsing and manipulating the full rendered HTML element. [2], [3]

Of course, this works but just didn’t feel right.

I thought, Instead of parse & manipulate the full rendered HTML fragment after

just define a global error html_options that will be merged into the AV::FormHelper object before.

So I started coding…

I’m not super happy with the current test setup. I wanted to avoid a lot of c&p for setup and teardown.

So I’ve oriented myself on the asset_tag_helper_test.rb dry pattern. Feedback, of course, is welcome!

I’ve summarized my work in this PR:

https://github.com/rails/rails/pull/31247

p.s. I apologize for sending this email after creating the PR!

Best,

Matthias

[1] https://github.com/rails/rails/pull/31088

[2] https://gist.github.com/Stex/5539836

[3] https://dreamconception.com/tech/rails-4-add-data-error-attribute-to-form-field-instead-of-using-wrapper/