modular-forms
modular-forms copied to clipboard
Cannot read properties of undefined (reading 'error')
I get the following error:
Cannot read properties of undefined (reading 'error')
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.
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.
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? 🙏
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.
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.
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 😅
May I see the Zod scheme? I would like to understand the problem in more detail.