fabian-hiller / modular-forms

The modular and type-safe form library for SolidJS, Qwik and Preact
https://modularforms.dev
MIT License
1.05k stars 55 forks source link

SolidJS: Unable to get values of fields that have never been active using `getValues(formStore, { shouldActive: false })` #157

Open eyemono-moe opened 11 months ago

eyemono-moe commented 11 months ago

minimal reproduction:

The documentation suggests using shouldActive: false with getValues() to retrieve values of inactive fields. However, when a <Field> is initially hidden and never becomes active, setting shouldActive to false does not allow retrieval of values for inactive fields.

In the above demo, only the email field is retrieved after the page loads, even though shouldActive is set to false. Clicking the "show password" checkbox makes the password field visible even after becoming inactive.

Moreover, similar to the issue of not being able to retrieve values for inactive fields with getValues, the reset does not work for fields that have never been active. In the demo, pressing the "Reset" button resets "reset email" and "reset password," but if the password field has never been active, pressing "Reset" does not change it to "reset password."

Is this the intended behavior?

fabian-hiller commented 11 months ago

This is a general problem with Modular Forms for SolidJS that I am trying to fix in January. The problem is that the library only initializes a field when you call setValue or add the props of <Field /> to an <input /> or <select /> element. Therefore, when you call getValues the library is not aware of these values.

As a workaround for now you can call setValue for each field in onMount or createEffect.