Skip to content

Instantly share code, notes, and snippets.

@arminyahya
Last active July 5, 2019 03:12
Show Gist options
  • Save arminyahya/7b8d7c2952719d4414fcae50cc3e6c83 to your computer and use it in GitHub Desktop.
Save arminyahya/7b8d7c2952719d4414fcae50cc3e6c83 to your computer and use it in GitHub Desktop.
final loginformstate
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