code-forge-io / code-forge-io/remix-hook-form

Cannot clear custom errors when returned by the server

Open
#12 8 comments 0 reactions 1 assignee Claimed by @AlemTuzlak View on GitHub
enhancement
Dominant language
TypeScript
Stars
453
Forks
43
PR merge metrics
No merged PRs in 30d

Description

Hello, thanks for the library!
Got a small issue

When i'm returning a custom error from the action as following:

```ts
export async function action({request, context, params}: ActionArgs) {

const {
data,
errors,
receivedValues ,
} = await getValidatedFormData(request, zodResolver(createSpaceInput))

try {
const result = context.api.onboarding.setUpSpace.mutate({
name: data.name
})

return json({ space: result })
} catch(e) {
return json({
errors: {
root: {
message: e.message
}
}
})
}
}
```

The error can be displayed just fine.
However, when i try to clear the error for example `onChange` it simply doesn't clear.

```ts
const form = useRemixForm({
mode: "onSubmit",
defaultValues: {
name: "",
},
resolver: zodResolver(formSchema),
});

{
console.log('form on change', form.formState.errors)
form.clearErrors('root')

}}>
```

I have also noticed that when I return an error which has the same name as one of the fields:

```ts
export async function action({request, context, params}: ActionArgs) {
... // rest of the function

return json({
errors: {
name: {
message: 'some backend error coming from external api'
}
}
})
}
```

It behaves the same way, as in the message is shown just fine, but it can't be cleared up

Any tips?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.