modular-forms icon indicating copy to clipboard operation
modular-forms copied to clipboard

Cannot read properties of undefined (reading 'error')

Open ffMathy opened this issue 1 year ago • 6 comments

I get the following error:

Cannot read properties of undefined (reading 'error')

image

When I try to use a "number" field ("durationInMinutes") like so in Qwik:

<Field name="durationInMinutes" type="number">
  {(field, props) => 
    <input type="number" {...props} />
  }
</Field>

Repo where this happens: https://github.com/ffMathy/poodle.lol/tree/38087c572c8ac3bdf401d401b48440adac05357c

Using latest version of modular-forms as of writing.

ffMathy avatar Jun 28 '23 06:06 ffMathy

Can you check if your initial values is invalid? The initial values is used to initialize the store of your form. If durationInMinutes is missing, the field cannot be initialized.

fabian-hiller avatar Jun 28 '23 10:06 fabian-hiller

Ah that's propably it. Will investigate when I get back from vacation and get back to you.

It would still be awesome with more descriptive error messages though. Perhaps throwing an exception would be helpful? 🙏

ffMathy avatar Jun 28 '23 11:06 ffMathy

I had some time to check now. That was indeed the cause! Leaving this open in case you want to still add an error message.

ffMathy avatar Jun 28 '23 13:06 ffMathy

I have thought from time to time about adding error messages with info. However, these should not be in the production build. I don't want to increase the bundle size because of that.

fabian-hiller avatar Jun 28 '23 21:06 fabian-hiller

Makes a lot of sense. The error also occurred because I had an any cast somewhere.

The reason for the any cast is that in my Zod schema, I have an array that requires at least 1 element. But the default value of course doesn't have one.

That gave me typing issues, which then ironically made it hard for me to see the error. But I think if the typing was there, it'd be easy. So you could argue it's not your fault 😅

ffMathy avatar Jun 29 '23 04:06 ffMathy

May I see the Zod scheme? I would like to understand the problem in more detail.

fabian-hiller avatar Jun 29 '23 09:06 fabian-hiller