Last active
April 3, 2018 13:18
-
-
Save kettanaito/0408b5e6bb13b3a748a108cfee8af93e to your computer and use it in GitHub Desktop.
React Advanced Form - Async validation
This file contains hidden or 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
import React from 'react'; | |
import { Form } from 'react-advanced-form'; | |
export default class RegistrationForm extends React.Component { | |
validateEmail = ({ value, fieldProps, fields, form }) => { | |
return fetch('https://backend/', { body: value }) | |
.then(res => res.json()) | |
.then((res) => { | |
return { | |
/* Determine if the e-mail is valid based on response */ | |
valid: (res.statusCode === 'SUCCESS'), | |
errorCode: res.errorCode | |
}; | |
}); | |
} | |
render() { | |
return ( | |
<Form> | |
<Input | |
name="userEmail" | |
type="email" | |
asyncRule={this.validateEmail} | |
required /> | |
{ /* Rest fields */ } | |
</Form> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment