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

Async step validation #8

Closed
jorgecuesta opened this issue Jan 27, 2017 · 8 comments
Closed

Async step validation #8

jorgecuesta opened this issue Jan 27, 2017 · 8 comments

Comments

@jorgecuesta
Copy link

Hi, first of all, great work. I start to use it and let more easy my life ;)

I need to make some validation with backend service in step component. What should I return on validated method ? maybe you can support a Promise.

@newbreedofgeek
Copy link
Owner

@jorgecuesta tnx. Glad you find this useful.

Yes I agree, the validation should support aync validation as well.

At the moment is only support sync validation. You return "true" to indicate that its valid and "false" if its not valid. Not returning anything (i.e. undefined) is treated as "true". The logic is here:
https://github.com/newbreedofgeek/react-stepzilla/blob/master/src/main.js#L170

Let me convert this request to a "enhancement" and see if I can upgrade it to support a Promise.

If you want to give it a go as well, please do and submit a Pull Request :)

@newbreedofgeek
Copy link
Owner

@jorgecuesta I've updated the validation to support Promises :)

Here is how you can use it:
https://github.com/newbreedofgeek/react-stepzilla/blob/master/src/examples/Step3.js#L22

It's in version 4.0.0 so make sure you npm update

@jorgecuesta
Copy link
Author

Thanks @newbreedofgeek by the quick solution 👍

@jorgecuesta
Copy link
Author

One note about async validation. Usually reject is used to handle wrong path like invalid state or error response.
I think the it should be resolve() for valid state and reject() for invalid state.
You don't really need a boolean value.

@newbreedofgeek
Copy link
Owner

newbreedofgeek commented Jan 30, 2017

Agree, I didn't use reject() due to a composability issue I had. But it is the right way to return false in this instance. Reopening this as a bug, I'll take a look when I have some time.

@newbreedofgeek
Copy link
Owner

@jorgecuesta it now supports resolve() and reject() correctly. Please try and let me know if any issues.

@jorgecuesta
Copy link
Author

@newbreedofgeek Thanks again! you became my hero! 👍
Now I wanna ask you if have a way to set Next button as disabled before component report a right validation state.
If you want I can open a new issue and can tag it as enhancement.

@newbreedofgeek
Copy link
Owner

Yes @jorgecuesta , pls open a new issue as a enhancement.

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

2 participants