Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async validation #122

Open
sholladay opened this issue Dec 19, 2019 · 2 comments
Open

Async validation #122

sholladay opened this issue Dec 19, 2019 · 2 comments

Comments

@sholladay
Copy link

This is a feature request to allow the validate() function to return a Promise for the validation result. A common use case is to perform an API request to check whether a username is unique in the database.

export default function SignUpForm() {
    const [state, { text }] = useFormState();
    return (
        <input
            {...text({
                name: 'username',
                validate: async (value) => {
                    const result = await checkUniqueUsername(value);
                    return result;
                },
                validateOnBlur: true,
            })}
            required
        />
    );
};
@jfennell-techempower
Copy link

I would love this functionality for this exact use case,

@jfennell-techempower
Copy link

Similarly, allowing the other input event handler functions to also be async would be very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants