pablo-abc / felte

An extensible form library for Svelte, Solid and React
https://felte.dev
MIT License
1.01k stars 44 forks source link

[Solid] Error: Cannot convert undefined or null to object when calling `validate` in `onMount` #138

Open m4rvr opened 2 years ago

m4rvr commented 2 years ago

Describe the bug

Hey! I have a form in a dynamic component which is shown and hidden based on the current view. When I change the view, the view with the form is unmounted and the existing errors disappear.

To solve this I want to re-validate the form in onMount so it shows the errors again when I switch to that view. But whenever I call validate I get this error in the console: CleanShot 2022-05-13 at 09 34 40 CleanShot 2022-05-13 at 09 39 08 The error seems to be at the touched.set call?

I also tried to reset the value and also set it as touched manually before but this doesn't work either.

The form only has one text input with a string value.

Let me know if you need a reproduction for it!

Which package/s are you using?

@felte/solid (SolidJS), @felte/reporter-solid, @felte/validator-zod

Environment

To reproduce

  1. Create form inside component
  2. Load the component dynamically so it unmounts and mounts again on change
  3. Call validate() inside Solid's onMount
    onMount(() => {
    validate()
    })
  4. Error happens when component mounts

Small reproduction example

No response

Screenshots

No response

Additional context

No response

pablo-abc commented 2 years ago

Are you setting the 'initialValues' option?

Without setting initialValues it might take an extra tick for Felte to set the stores.

Although I'd have expected that to already be available in onMount. I'll look into that.

m4rvr commented 2 years ago

Sorry, yes, I am setting the initialValues. It's based on a value from a context.