-
Notifications
You must be signed in to change notification settings - Fork 21.6k
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for override of field_error_proc in the FormBuilder #39522
Comments
@thebravoman this seems like a good idea and would be a way for engines like Refinery not to stomp on an application's settings as they could create a custom form builder for its UI and just override it there. Is this something you want work on? |
@pixeltrix yes, I could look at it and prepare a PR. |
Hey there! I just wanted to follow up on this idea. How can I be of help here? |
Thanks @jacobbednarz . We talked in the forum. I will try to look at this by the end of August. |
Okay! If there’s anyway I could help, please let me know. |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
Hey, @jacobdaddario @pixeltrix I wanted to share that I am thinking on an approach to have the logic in the FormBuilder. I have proposed an implementation. As per Rails Contribution guides I would like to first get feedback before opening a new PR. Let me know your thoughts in https://discuss.rubyonrails.org/t/feature-allow-for-override-of-field-error-proc-in-the-formbuilder-could-prepare-pr-if-the-approach-is-reasonable/79843 |
I'm so happy that you came back to this issue. Trying to extract |
Create a form with a custom builder. Generate input fields with additional labels and classes in the form builder. When an active record validation error occurs the ActionView::Base.field_error_proc is called that wraps the field with a span and a class.
But we should be able to override field_error_proc in the FormBuilder since this is where we are building the forms. In my case the field_error_proc was even defined by another engine, so it made it more difficult to debug why an additional span was added. The additional span was breaking the functionality because of the way the toggle checkboxes were generated.
Steps to reproduce
The builder in my case has the following method.
Actual behavior
It generates
This works very well until there is an error in the form. Then the generated html is
Notice the additional
<span class="fieldWithErrors">
. Because of this span the checkbox is no longer working.If there is an error we are calling Base.field_error_proc
and in my case this field_error_proc was defined in another engine used by the host app- refinery
Expected behavior
I am sure there are ways to hack around this in the collection_check_boxes and generate the field in a different way, but I think active model helper should first call a method of the FormBuilder and probably after that delegate to Base.field_error_proc. This would allow us to override the error classes for a specific form. Because if I now just disable this proc I would break the functionality provided by a different engine.
System configuration
Rails version: 6.0.3.1
Ruby version: 2.6.5
The text was updated successfully, but these errors were encountered: