-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Cannot clear custom errors when returned by the server #12
Comments
@fenos Hello! The issue you're facing is the fact that when you return the remix errors from the backend they are consumed internally by the hook until they are cleared in the |
Any progress on this? I have just come across the same issue. If you have a recommend solution I can implement it for you. |
@Centerworx i think the solution is to have a simple setState that is set to true on submit and false on reset and depending on that it consumes the be errors |
@AlemTuzlak Working on it. There is an issue around useActionData return the value before submit true is set. Even though it is set to true before calling submit handler. But this may just be test implementation issue. |
@AlemTuzlak I have the fix done and tested. I'm having an issue pushing it. Problem with my git. |
Hi, first of all, thanks to @AlemTuzlak for making remix-hook-form. I used usePrevious in the project to get the difference of serverErrors and then merged it, which temporarily solved the problem. const errors = data?.errors || emptyErrors
const [serverErrors, setServerErrors] = React.useState(() => errors)
const previousServerErrors = usePrevious(serverErrors)
const formErrors = React.useMemo(() => {
const keys = Object.keys(serverErrors)
const prevKeys = previousServerErrors ? Object.keys(previousServerErrors) : []
const deletedErrorKeys = prevKeys.filter((key) => !keys.includes(key))
const localErrors = methods.formState.errors as FieldErrors<Output>
const mergedErrors = mergeErrors<Output>(localErrors, serverErrors, validKeys)
for (const key of deletedErrorKeys) {
delete mergedErrors[key]
}
return mergedErrors
}, [methods.formState.errors, previousServerErrors, serverErrors, validKeys])
React.useEffect(() => {
if (isSubmitting) {
setServerErrors(emptyErrors)
} else {
// Only update the server errors if the form is not submitting
setServerErrors(errors)
}
}, [errors, isSubmitting]) |
Is there any progress on this? I just run into the same issue. |
So this might be potentially fixed with the fact that I moved to using the react-hook-form native "errors" prop, can anyone confirm? |
Hello, thanks for the library!
Got a small issue
When i'm returning a custom error from the action as following:
The error can be displayed just fine.
However, when i try to clear the error for example
onChange
it simply doesn't clear.I have also noticed that when I return an error which has the same name as one of the fields:
It behaves the same way, as in the message is shown just fine, but it can't be cleared up
Any tips?
The text was updated successfully, but these errors were encountered: