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

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

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

M. Neumayr
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 
<div class="field_with_errors">[…]</div> easy add a custom css 
class (or data-attr.) _to_ the input element itself.

like: <input type="text" class="is-invalid" value="invalid-blabla" />
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:

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


[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/

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.