Skip to content

Instantly share code, notes, and snippets.

@ademidoff
Last active February 10, 2017 01:44
Show Gist options
  • Save ademidoff/f022443cb48bb4cf6c66ea851e588623 to your computer and use it in GitHub Desktop.
Save ademidoff/f022443cb48bb4cf6c66ea851e588623 to your computer and use it in GitHub Desktop.
Redux Form Async Validation
export default reduxForm({
form: 'signIn',
asyncValidate: (values) => {
return new Promise((resolve, reject) => {
// simulate request
setTimeout(() => {
if (values.email.indexOf('@gmail.com') === -1) {
reject({ email: 'Only mails at gmail are allowed' });
} else {
resolve();
}
}, 1000);
});
},
asyncBlurFields: ['email'],
shouldAsyncValidate: (params) => {
return params.trigger === 'blur' && params.syncValidationPasses; // do not async validate on submit
}
})(MyForm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment