jurassix / react-validation-mixin

Simple validation mixin (HoC) for React.
MIT License
283 stars 38 forks source link

Validate callback called twice? #40

Closed idolize closed 8 years ago

idolize commented 8 years ago

I just updated from 4.x to 5.x and code that I had previously been using is now observing odd behavior.

I was previously using code that looked like this:

this.props.validate(error => {
  if (error) {
    return alert('Validation errors');
  }
  sendDataToServer(data);
});

...but I noticed that the callback to validate is being called twice (and thus submitting my data twice) for one call to the validate method.

(This was not the behavior for 4.x)

Right now, I'm using a workaround that looks like this:

let submitting = false;
this.props.validate(error => {
  if (error) {
    return alert('Validation errors');
  }
  if (!submitting) {
    sendDataToServer(data);
  }
  submitting = true;
});

but it'd be great to not have to do this :smile:

CrisLi commented 8 years ago

+1

jurassix commented 8 years ago

What are the versions of the mixin and strategy are you using?

jurassix commented 8 years ago

There was a bug in the joi-validation-strategy please upgrade to version 0.1.1 to resolve this issue.

idolize commented 8 years ago

@jurassix Thanks for the quick fix! I love the changes in 5.x btw

CrisLi commented 8 years ago

@jurassix It fixed, thanks a lot.