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

Update nextButtonClick() with Async! #25

Closed
peter-sorbo opened this issue Jul 25, 2019 · 1 comment
Closed

Update nextButtonClick() with Async! #25

peter-sorbo opened this issue Jul 25, 2019 · 1 comment

Comments

@peter-sorbo
Copy link

I want to provide some clarification or help to people using the wizard with HTTP requests. Hopefully the docs could be updated to clarify how isValidated() works or how to use it with async.

DETAILS: I've been using the Wizard to validate a Login request. i.e. axios.post('/login') -> if username & password are ok -> next step, else -> throw validation error. What I didn't realize is that isValidated() is being called by nextButtonClick() which is synchronous, so it doesn't wait for the HTTP request to resolve before changing steps. Simply adding async to NextButtonClick() lets it wait for the request to resolve, and allows you to use HTTP requests with the wizard.

Hope this saves you some frustration!

NextButtonClick()

  async nextButtonClick() {
  if (
  (this.props.validate &&
    ((this.refs[this.props.steps[this.state.currentStep].stepName]
      .isValidated !== undefined &&
      await this.refs[
        this.props.steps[this.state.currentStep].stepName
      ].isValidated()) ||
      this.refs[this.props.steps[this.state.currentStep].stepName]
        .isValidated === undefined)) ||
  this.props.validate === undefined ||
  !this.props.validate
)

isValidated()

async isValidated() {
    let response = await axios.post('http://0.0.0.0:8080/accounts?action=submit', {
       username: this.state.username,
       password: this.state.password,
       api_type: this.props.wizardData['Select Device Type'].api_type
    })

if (response.Status===200) {
	return true
} else {
	return false
}

}

@spoecker
Copy link

Any plans on updating the plugin anytime soon?

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

3 participants