Last active
October 19, 2022 10:55
-
-
Save IniZio/19799397d26e35fe27ee0da164195acf to your computer and use it in GitHub Desktop.
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
function Demo() { | |
const loginForm = useForm({ | |
email: ['', [Validators.required]], | |
username: ['', [Validators.required, AsyncUsernameUniquenessValidator]], | |
password: ['', [PasswordStringValidator]], | |
contacts: [[], [Validators.minLength(1)], | |
); | |
const onLogin = useCallback((values) => { | |
console.log("=== form values", values); | |
}) | |
return ( | |
<form onSubmit={loginForm.handleSubmit(onLogin)}> | |
<Field field={loginForm.controls.email}> | |
{({ handlers, touched, errors }) => ( | |
<div className="form-group"> | |
<input {...handlers('text')} /> | |
<span> | |
{touched && errors.required && 'Email is required'} | |
</span> | |
</div> | |
)} | |
</Field> | |
<Field field={loginForm.controls.username}> | |
{({ handlers, pending, touched, errors }) => ( | |
<div className="form-group"> | |
<input {...handlers('text')} /> | |
{pending && <Loading />} | |
<span> | |
{touched && errors.required && 'Email is required'} | |
</span> | |
</div> | |
)} | |
</Field> | |
<button | |
disabled={ | |
!loginForm.touched | |
|| loginForm.pending | |
|| loginForm.invalid | |
|| loginForm.submitting | |
} | |
type="submit" | |
>Register</button> | |
</form> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment