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: Form reset action doesn't preventDefault like submit does. #186

Open sid1029 opened 8 months ago

sid1029 commented 8 months ago

I have an example here : https://stackblitz.com/edit/solidjs-templates-7pgd2x?file=src%2FApp.tsx

To observe the issue click reset.

What happens : form values disappear. Expected behavior: Clicking reset should reset the form to its initialValues.

I was stuck on this for a while. The onReset action on a form doesn't seem to preventDefault() its event the way the submit handler does for you.

This causes the native browser behavior to override the behavior of the reset() function provided by modular-forms.

I would expect to just be able to call reset(formState) in the reset handler on a <Form> element and have the fields go back to their initialValues. But if I don't explicitly event.preventDefault() first, the browser resets the fields to blank values in the UI. The underlying formState model maintained by modular-forms correctly reflects the initialValues after reset().

Maybe my expectation is wrong but if I'm using the <Form> element generated by modular-forms instead of the native HTML <form> element I would expect things are really handled end-to-end by the library for me.

PS: This is a great library ! I'm using this with solid-bootstrap.

fabian-hiller commented 8 months ago

Thank you very much! That is a good point. Unfortunately, I have less time for Modular Forms at the moment, but this is something I will consider for the future of the library.