Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise support for onSubmit #28

Closed
marshallswain opened this issue Jan 17, 2017 · 9 comments
Closed

Promise support for onSubmit #28

marshallswain opened this issue Jan 17, 2017 · 9 comments

Comments

@marshallswain
Copy link
Contributor

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.

@marshallswain marshallswain changed the title Promise support for onSubmit and postSubmit Promise support for onSubmit Jan 17, 2017
@tannerlinsley
Copy link
Collaborator

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

@vutran47
Copy link

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)

@tannerlinsley
Copy link
Collaborator

tannerlinsley commented Mar 21, 2017 via email

@chuan137
Copy link

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.

@marshallswain
Copy link
Contributor Author

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

@thomas-p-wilson
Copy link

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

@joepuzzo
Copy link
Contributor

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

@joepuzzo
Copy link
Contributor

Async validation now supported!

@seniorquico
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants