remix-validated-form
remix-validated-form copied to clipboard
[Bug]: All server errors get cleared after focus changes or any field value changes
Which packages are impacted?
- [X]
@rvf/react
- [X]
@rvf/remix
- [ ]
@rvf/zod
- [ ]
@rvf/yup
- [ ]
zod-form-data
What version of these packages are you using?
- "@rvf/react": "^6.1.4",
- "@rvf/remix": "^6.1.3",
- "@rvf/zod": "^6.0.3",
Please provide a link to a minimal reproduction of the issue.
https://stackblitz.com/edit/remix-run-remix-g89vpl?file=app%2Froutes%2F_index.tsx
Steps to Reproduce the Bug or Issue
Go to https://stackblitz.com/edit/remix-run-remix-g89vpl?file=app%2Froutes%2F_index.tsx
Instructions:
- Enter valid email
- Enter valid password (at least 6 chars)
- Press enter while focus is in password field
Form will load, get errors from backend, but then email field will be focused and server errors will be cleared for all fields. This happens whenever the following 3 are true:
- @rvf/react focuses the first field with errors
- There was another field focused before
- These are not the same field
This can be confirmed by viewing the error history below.
If you press "Create account" without focus being in any field, then errors show up correctly. But again, as soon as you focus another field, focus no field, or change the value in 1 field, all backend are cleared.
Expected behavior
Ideally all server errors would be kept visible until that field is modified.
I think it's support for server validation errors should be as good as client side validation errors.
Related to this: It would be great (and I think kinda necessary if this library is meant to be independent of Remix) if it's also possible to show server validation errors on specific fields when not using remix actions.
When only using @rvf/react
, I couldn't find any docs mentioning how to support server validation errors (after the form is submitted).
I tried using serverValidationErrors
(which btw gives a type error when useForm
is imported from @rvf/remix
, but works when it's imported from @rvf/react
), but it has the same issue described above: all the errors are cleared when focus changes or a field is modified.
react-hook-form
has the setError
API and has the behavior I described above about errors not clearing until a field is changed.
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome
- Version: 128.0.6613.120
Additional context
No response