react-multi-email icon indicating copy to clipboard operation
react-multi-email copied to clipboard

Async Email Validation

Open Seth10001 opened this issue 4 years ago • 1 comments

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>
        );
    }}
    />

Seth10001 avatar Aug 25 '20 16:08 Seth10001

I made a PR to support async-validate.

https://github.com/jsdevkr/react-multi-email/pull/59

jopemachine avatar Sep 17 '20 05:09 jopemachine