Skip to content
Source
Sign inSign up
TanStack/form

Promise support for onSubmit #28

Send to my agent
Closedmarshallswain(GitHub profile, opens in a new tab) opened this issue 9 comments

I'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.

  • onSubmitSuccess would run if the promise resolves.
  • onSubmitError would 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.

  1. This is super interesting. I'll start looking into the possibilities in the code and keep you up to date here.

  2. tannerlinsley added labelshelp wanted

  3. At this state, postSubmit is also pretty useless since it will be called anyway without the results. My current workaround is to call resetForm manually since it's the 4th argument passed to submit. This is very much an implementation detail and should not be used this way.

    submit = (v, s, p, f) => submit(v).then(f.resetForm)
  4. 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> .

  5. 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, onSubmit and postSubmit functions 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.

  6. Yep. @chuan137's got me. Inspired by Feathers.

  7. As a feathers user, I am most definitely in favour!

  8. Working on getting V2 rolled out soon. This supports Asynchronous validation. Stay tuned!

  9. Async validation now supported!

  10. It appears async submit is now supported, too! (Similar to the proposal found in this issue.)

Sign in to join this conversation.