-
Notifications
You must be signed in to change notification settings - Fork 25
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
Revalidate (or at least clean) server errors on input change #126
Conversation
✅ Deploy Preview for remix-forms ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
This approach LGTM 💪🏼 |
…other branch when errors are set on the server only. This will allow for client-side cleaning of server generated errors (though we can't really revalidate without submitting).
a8a2705
to
a820575
Compare
@@ -262,9 +262,9 @@ function createForm({ | |||
|
|||
const fieldErrors = (key: keyof SchemaType) => { | |||
const message = (formErrors[key] as unknown as FieldError)?.message | |||
return (message && [message]) || (errors && errors[key]) | |||
return browser() ? (message && [message]) : (errors && errors[key]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about the case when the user sets the errors
prop on the Form?
I think it will both be in the browser and have this errors[key]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felipefreitag, in that case, we would have set the form error in the client here. We get the error from the prop, action data or fetcher data and set it on the client.
The only reason we still return (errors && errors[key])
is for when JS is disabled.
Purpose
If we get an error coming from the server action and render it as a field error, it's safe to assume that upon changing that field value we should cease to see the error.
Since an error depends on the field and its value, and changing the value turns the error to an unknown state.
This should address #111.
Note that with the current shape of this PR is that we can't really revalidate unless we resubmit the form, and doing this on behalf of the user would be reckless at best.
It seems safer to clean the error state and allow the user to resubmit to get a new validation from the server.
TODO: