react-multi-email
react-multi-email copied to clipboard
Async Email Validation
I would like to validate an email's uniqueness asynchronously using an API call. If the validateEmail
prop accepted promises then this could be done easily.
For example:
<ReactMultiEmail
style={{ minHeight: '100px' }}
emails={emails}
onChange={(_emails: string[]) => {
this.setState({ emails: _emails });
}}
validateEmail={async (email) => {
let response = await axios.get('/api/valid-email', { params: { email: email }})
//{.... data: { valid: true } .... }
return response.data.valid
}}
getLabel={(
email: string,
index: number,
removeEmail: (index: number) => void,
) => {
return (
<div data-tag key={index}>
{email}
<span data-tag-handle onClick={() => removeEmail(index)}>
×
</span>
</div>
);
}}
/>
I made a PR to support async-validate.
https://github.com/jsdevkr/react-multi-email/pull/59