mantine
mantine copied to clipboard
[@mantine/form] zod-resolver doesn't handle asynchronous validation
What package has an issue
@mantine/form
Describe the bug
First of all, thank you for the amazing work done on Mantine 4.0 🙏
I my current project, I am making heavy use of form validation through zod and in some cases I have a need for asynchronous validation, eg:
const signupSchema = z
.object({
username: z
.string()
.refine(
value =>
axios
.post('/api/check_unique_username', { username: value })
.then(() => true)
.catch(() => false),
{
message: 'Username already exists',
},
),
});
However, this doesn't work with the current implementation of zodResolver because it uses the safeParse method (see here).
In which browser did the problem occur
All of them
If possible, please include a link to a codesandbox with the reproduced problem
No response
Do you know how to fix the issue
Yes
Are you willing to participate in fixing this issue and create a pull request with the fix
Yes
Possible fix
Replace the call to safeParse by a call to safeParseAsync in zodResolver
You can send a PR to the master branch
Is anyone working on this? i see https://github.com/mantinedev/mantine/pull/1255 is closed..