auto-form icon indicating copy to clipboard operation
auto-form copied to clipboard

Missing onParsedValuesChange function in AutoForm component

Open nicolasdonato opened this issue 1 year ago • 6 comments

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.

nicolasdonato avatar Oct 24 '24 12:10 nicolasdonato

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);
      }
    });
  }}
/>

vantezzen avatar Oct 24 '24 13:10 vantezzen

Thank you, this is working good.

nicolasdonato avatar Oct 25 '24 12:10 nicolasdonato

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

nicolasdonato avatar Oct 28 '24 16:10 nicolasdonato

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

vantezzen avatar Oct 29 '24 20:10 vantezzen

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 ?

nicolasdonato avatar Oct 30 '24 13:10 nicolasdonato

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.

nicolasdonato avatar Oct 31 '24 14:10 nicolasdonato