Skip to content
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

Missing onParsedValuesChange function in AutoForm component #125

Open
nicolasdonato opened this issue Oct 24, 2024 · 6 comments
Open

Missing onParsedValuesChange function in AutoForm component #125

nicolasdonato opened this issue Oct 24, 2024 · 6 comments

Comments

@nicolasdonato
Copy link

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.

@vantezzen
Copy link
Owner

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

@nicolasdonato
Copy link
Author

Thank you, this is working good.

@nicolasdonato
Copy link
Author

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

@vantezzen
Copy link
Owner

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

@nicolasdonato
Copy link
Author

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants