You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using #empty? is a common pattern to check if a form object has any errors or not. For example this method is also used when calling #present?. It should return true if there are no errors and false otherwise.
Currently I'm working on an application that requires adding errors to the form after it was validated. However, adding an error after validating the form does not change the status of #empty?. The following example demonstrates the problem:
The last call to #empty? should return false. The same issue also exists when adding a new error to a nested form.
Currently #empty? only checks for the @success instance variable. My first idea was to set this instance variable to false once #add is called on the form's errors. However, this won't work for nested forms because the "parent"-form still does not know about the nested error. Maybe there is another better way of solving this issue?
The current workaround for me is to call validate({}) after adding the errors to ensure the new errors are "recognized" by the form.
The text was updated successfully, but these errors were encountered:
This definitely comes with some performance penalty. I guess there is a simpler way to do this.
richardboehme
changed the title
#empty? does not update if error added via `#errors.add(...)#empty? does not update if error added via #errors.add(...)Aug 18, 2023
Using
#empty?
is a common pattern to check if a form object has any errors or not. For example this method is also used when calling#present?
. It should return true if there are no errors and false otherwise.Currently I'm working on an application that requires adding errors to the form after it was validated. However, adding an error after validating the form does not change the status of
#empty?
. The following example demonstrates the problem:The last call to
#empty?
should return false. The same issue also exists when adding a new error to a nested form.Currently
#empty?
only checks for the@success
instance variable. My first idea was to set this instance variable to false once#add
is called on the form's errors. However, this won't work for nested forms because the "parent"-form still does not know about the nested error. Maybe there is another better way of solving this issue?The current workaround for me is to call
validate({})
after adding the errors to ensure the new errors are "recognized" by the form.The text was updated successfully, but these errors were encountered: