Last active
December 22, 2018 19:01
-
-
Save malerba118/b4d042e03d2f585134acd37d9524764b to your computer and use it in GitHub Desktop.
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
| const form = useForm({ | |
| onSubmit, | |
| }); | |
| const usernameField = useField("username", form, { | |
| defaultValue: "", | |
| validations: [ | |
| async formData => { | |
| await timeout(2000); | |
| return formData.username.length < 6 && "Username already exists"; | |
| } | |
| ], | |
| fieldsToValidateOnChange: [] | |
| }); | |
| const passwordField = useField("password", form, { | |
| defaultValue: "", | |
| validations: [ | |
| formData => | |
| formData.password.length < 6 && "Password must be at least 6 characters" | |
| ], | |
| fieldsToValidateOnChange: ["password", "confirmPassword"] | |
| }); | |
| const confirmPasswordField = useField("confirmPassword", form, { | |
| defaultValue: "", | |
| validations: [ | |
| formData => | |
| formData.password !== formData.confirmPassword && | |
| "Passwords do not match" | |
| ], | |
| fieldsToValidateOnChange: ["password", "confirmPassword"] | |
| }); | |
| // const { onSubmit, getFormData, addField, isValid, validateFields, submitted, submitting } = form | |
| // const { name, value, onChange, errors, setErrors, pristine, validate, validating } = usernameField |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment