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

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

Open eyemono-moe opened this issue 1 year ago • 1 comments

minimal reproduction:

  • repo: https://github.com/eyemono-moe/modular-forms-reset
  • live demo: https://modular-forms-reset.trap.show/
  • stackblitz: https://stackblitz.com/~/github.com/eyemono-moe/modular-forms-reset

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?

eyemono-moe avatar Dec 09 '23 08:12 eyemono-moe

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.

fabian-hiller avatar Dec 09 '23 16:12 fabian-hiller