Skip to content

Instantly share code, notes, and snippets.

@arminyahya
Created July 5, 2019 03:37
Show Gist options
  • Save arminyahya/6f9366e286847c4ed3479def921a0c32 to your computer and use it in GitHub Desktop.
Save arminyahya/6f9366e286847c4ed3479def921a0c32 to your computer and use it in GitHub Desktop.
loginformstate with validators
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