Comments (1)
A TypeScript example
import React, { Component } from 'react';
import { Button, Container, Entry } from '../components';
import { observer } from 'mobx-react';
import FormStore, { Validators } from 'mobx-valite-form-store';
export type LoginEntries = {
username: string;
password: string;
};
export type LoginFormProps = {
passwordRecoveryURL: string;
onLogin: (entries: LoginEntries) => void;
};
const validators: Validators<LoginEntries> = {
username: [
(value: string) => !!value.trim() || 'Nome de usuário vazio.',
(value: string) => value.length > 18 || 'Nome de usuário maior que o permitido.'
],
password: [
(value: string) => !!value.trim() || 'Senha vazia.',
(value: string) => value !== '123456' || 'Senha de usuário muito fácil, use outra.'
]
};
@observer
export class LoginForm extends Component<LoginFormProps> {
store: FormStore<LoginEntries> = new FormStore({}, validators);
onPress = async () => {
await this.store.validateEntries();
if (this.store.isValid && !this.store.isLoading)
return;
this.props.onLogin(this.store.entries);
};
render () {
return (
<Container>
<Entry
label="Nome de Usuário"
value={ this.store.entries.username }
message={ this.store.errors.username }
onChange={ (value) => this.store.setEntry('username', value) }
/>
<Entry
label="Senha"
value={ this.store.entries.password }
message={ this.store.errors.password }
onChange={ (value) => this.store.setEntry('password', value) }
/>
<Link to={ this.props.passwordRecoveryURL }>Esqueceu sua senha?</Link>
<Button onPress={ this.onPress } isDisabled={ !this.store.isValid || this.store.isLoading }>
Entrar
</Button>
</Container>
);
}
}
from mobx-valite-form-store.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mobx-valite-form-store.