HandleSubmit Promise resolve isValid
Problem to solve
In my use case, I have several forms and each form appears if the previous one is valid. I use handleSubmitfor each form and as it returns a promise, I was expected than I can check inside an object or a value to see if the form is valid, but I got undefined.
My current workaround for anyone who's interested:
return handleSubmit().then(() => {
return $isValid
});
Proposal
The handleSubmit promise could return some information, at least a bool that specifies whether the form is valid or not.
What do you think of this?
@kiuKisas it seems what you're looking to do is to sequentially submit forms if a previous form's values are valid and have been submitted, and without waiting for the response from your onSubmit function - does that sound correct?
Hum, to add some context, I have a huge forms separate in 3 tiny forms, each forms are sequentially shown after the previous one was submit and valid, displayed as a "slider" like interface.
So I have a main component which contain the "slider-like" logic, with navigation (submit button, "next" then "send" when all the forms are filled & valid).
The 3 forms are 3 different components which export a validate function (as I describe previously) to let the main component known if the current form is valid or not when the user click on the navigation (and so, go to the next slide/form or stay at the current one).
Currently I don't use the onSubmit callback from svelte-forms-lib as I need to export this logic to a parent component. Probably not the expected usage though.
I was just expected that the promise from handleSubmit says something about the current state of the form and I think it should, resolving undefined doesn't feel right to me.
What do you think about that ?
@kiuKisas I like the idea of returning something with the resolved promise, I'm not sure that returning $isValid feels right, though. It may be odd to get the validity of form values after submitting a form.
Perhaps returning a plain boolean would describe a clear intent: Will the form submit? Yes / No.
We'll need some tests to cover 3 situations (as per these lines: https://github.com/tjinauyeung/svelte-forms-lib/blob/master/lib/create-form.js#L115-L152):
- the user provided a validation function
- the user provided a validation schema
- the user didn't provide either
Would you like to make a PR?
Sorry, I was busy these days and forgot about it. Sure, I'll have a look when I find time and let you know :)