Missing onParsedValuesChange function in AutoForm component
Hello,
I am working on the migration of AutoForm and I have this issue.
I used in my forms the attribute name onParsedValuesChange but it seems this attribute has disapeared.
Could you please tell if we can use the same behavior with other attribute ?
I thank you in advance.
This doesn't currently exist because it sometimes worked unreliable - but I'll add it in the future.
In the meantime you can hook into react-hook-form directly, it should work like this:
<AutoForm
onFormInit={(form) => {
form.watch((data) => {
const parsedData = schema.safeParse(data);
if (parsedData.success) {
onParsedValueChange(parsedData.data);
}
});
}}
/>
Thank you, this is working good.
Another question : I used the form.watch ans schema.safeParse functions.
When I checked the data which is defined into args watch method, I didn't have a setting value as enum, like this:
const schema = z.object({
"level": z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]).default("6")
})
<AutoForm
schema={new ZodProvider(schema)}
onFormInit={(form) => {
form.watch((data) => {
const parsedData = schema.safeParse(data);
if (parsedData.success) {
handleOnParserValuesChange(parsedData.data);
}
});
}}
/>
Here the value into level is undefined and I don't know why.
Does you have any idea, please ?
Thank you in advance
I don't think I fully understand you issue - I tried running this code but the values I got looked correct: https://codesandbox.io/p/sandbox/autoform-mui-demo-3pjwvr
The same code does not work into my workspace. I do not know why. Maybe it is linked to the usage of the latest version of shadcn ?
Ok I have the same issue but I can have a workaround like this
const schema = z.object({
"level": z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]).default("6")
})
<AutoForm
schema={new ZodProvider(schema)}
formProps={
onChange: (e) => {
console.log(e);
}
}
/>
I do not know why I can have the good value like this and not with the method form.watch method.