-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
formStore.setError() with nested values completely broken #3607
Comments
Happy to make a PR for this, just need to know whether to simply remove the Array / Object check or add an extra param to dictate when to skip that check (looks like it needs to be skipped for touched too). I've patched the package with the extra param method for now. I don't think it would hurt if it set values too, but not 100% sure that won't break anything |
We still don't have examples/tests with array fields, so I think creating one with some tests would be a good starting point. |
Current behavior
formStore.setError() does not properly set errors to the deepest nested property. It instead sets the error given on the top level property, which prevents FormError from ever having a chance at working.
Steps to reproduce the bug
Expected behavior
Properly traverses the nested arrays / objects and sets the requested named error so that FormError displays it.
Workaround
There are a few theoretical workarounds, none of those I have tried yet have worked. The most painful ( and likely to work) workaround I have yet to try is preventing the normal validation flow and manually setting errors with
setErrors()
since that is a simple replace in coreIf you do not use arrays, you can initialize the errors object with the entire object chain, which seems to work.
Possible solutions
Adjust the following lines to always ensure that if there are more rest properties, they get traversed and set to empty objects / arrays as necessary.
ariakit/packages/ariakit-core/src/form/form-store.ts
Lines 59 to 73 in 6346eee
I'm not sure if there's a reason that this function doesn't always do this, but it may be for reusability when the nested objects / arrays should already exist.
The text was updated successfully, but these errors were encountered: