Created
July 5, 2019 03:37
-
-
Save arminyahya/6f9366e286847c4ed3479def921a0c32 to your computer and use it in GitHub Desktop.
loginformstate with validators
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
import { FormState, FieldState } from 'formstate'; | |
export default class LoginFormState { | |
username = new FieldState('').validators((val) => !val && 'username required'); | |
password = new FieldState('').validators((val) => !val && 'password required'); | |
form = new FormState({ | |
username: this.username, | |
password: this.password | |
}); | |
onSubmit = async () => { | |
const res = await this.form.validate(); | |
if (res.hasError) { | |
console.log(this.form.error); | |
return; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment