shakacode / re-formality

Form validation tool for reason-react
https://re-formality.now.sh
MIT License
244 stars 35 forks source link

Provide option to not reset form on submit #11

Closed kgoggin closed 6 years ago

kgoggin commented 6 years ago

I can definitely understand resetting the form after a successful submit as the default behavior, but it'd be great if there were a way to prevent this in some cases. For instance, I'm working on a form that provides filter values for a list of data. On submit, the list gets refreshed with the new filter values... but my form resets so loses the user's input. I'd rather have it keep the same state after submitting.

I think it'd make sense to pass this option as a prop to the generated form component, and that way it could even change at runtime if desired. I tried implementing it a little in my own fork but was running into an issue of some kind. But, if that sounds like the right direction to you, I'd be happy to work on a PR for it. Thanks!

alex35mil commented 6 years ago

@kgoggin Yeah, agreed. I already started working on form status implementation. It should solve this kind of issues.

Basically, form status type will be something like this:

type formStatus = 
| Editing
| Submitting
| Submitted(option('data))
| SubmissionFailed(list(('field, fieldStatus)));

And I will expose reset handler so users will be able to trigger it manually in case if they want to reset the form or keep success message on the screen or whatever.

This is related to this discussion: https://reasonml.chat/t/preferable-form-validators-api/240/14?u=alexfedoseev

alex35mil commented 6 years ago

re-formality 0.7.0 published. Let me know if you find any issues!