Last active
July 17, 2018 12:55
-
-
Save neurodynamic/25c6537ff28d5577f319 to your computer and use it in GitHub Desktop.
AJAX validation with redux-form example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* EXPLANATIONS/EXAMPLES THAT MAY PROVIDE HELPFUL REFERENCE | |
http://erikras.github.io/redux-form/#/examples/asynchronous-blur-validation | |
https://github.com/erikras/react-redux-universal-hot-example/blob/b46921a990991e85522dbfc3195a46490a8f4e90/src/components/SurveyForm/SurveyForm.js | |
https://github.com/erikras/redux-form/issues/119 | |
*/ | |
// Working function with real request | |
export function asyncValidate (data) { | |
if (!data.email) { | |
return Promise.resolve({}) | |
} | |
return new Promise((resolve, reject) => { | |
$.get( | |
window.location.origin + | |
'/email_is_unique', | |
{email: data.email} | |
).done( | |
function (response) { | |
if (response === false) { | |
reject({email: 'This email has already been taken'}) | |
} else { | |
resolve() | |
} | |
} | |
) | |
}) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment