Promise support for onSubmit #28
Send to my agentI've put some more thought into async support and have identified another area where it would be very useful. It would be nice to have Promise support built into form.js, here: https://github.com/tannerlinsley/react-form/blob/master/src/form.js#L137
So, onSubmit could accept a function that returns a promise. We could create two lifecycle methods for handling the promise.
onSubmitSuccesswould run if the promise resolves.onSubmitErrorwould run if the promise is rejected.
Adding promise support to onSubmit would also make it possible to support standardized error messages from the server. So the server could send back an error object with a message property that could show up in the UI, automatically.
marshallswain(GitHub profile, opens in a new tab) changed the title
tannerlinsley added labelshelp wanted
At this state,
postSubmitis also pretty useless since it will be called anyway without the results. My current workaround is to callresetFormmanually since it's the 4th argument passed tosubmit. This is very much an implementation detail and should not be used this way.submit = (v, s, p, f) => submit(v).then(f.resetForm)Feathers? Wha do you mean?
On Tue, Mar 21, 2017 at 3:25 PM Chuan Miao <notifications@github.com> wrote:
I smell feathers here :)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub <https://github.com/tannerlinsley/react-form/issues/28#issuecomment-288223881>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AFUmCVanFycesInBw8LeDl2-UogQvy_xks5roEBRgaJpZM4Ll_fu> .
It is a light joke, I deleted it, because feathersjs is not so popular that everyone will get it :) But this is the background
This proposal will make
preSubmit,onSubmitandpostSubmitfunctions like the hooks in feathersjs, each of them will return a promise and they would await the async action of the previous hook.And I think @marshallswain is one of the authors of feathersjs.
Yep. @chuan137's got me. Inspired by Feathers.
As a feathers user, I am most definitely in favour!
Working on getting V2 rolled out soon. This supports Asynchronous validation. Stay tuned!
Async validation now supported!
joepuzzo(GitHub profile, opens in a new tab) closed this
It appears async submit is now supported, too! (Similar to the proposal found in this issue.)
Sign in to join this conversation.
This is super interesting. I'll start looking into the possibilities in the code and keep you up to date here.