I'm building a simple login form with Semantic UI in conjunction with React in ES6 JS. The code below functions as expected. I would like to know if I'm doing things in the right way and following React convention:
constructor(props) {
super(props);
// this is getInitialState()
this.state = {
emailaddress: '',
password: '',
errors: ''
};
}
componentDidMount() {
$('.ui.form').form({
fields: {
email: {
identifier : 'emailaddress',
rules: [
{
type : 'empty',
prompt : 'Please enter your e-mail'
},
{
type : 'email',
prompt : 'Please enter a valid e-mail'
}
]
},
password: {
identifier : 'password',
rules: [
{
type : 'empty',
prompt : 'Please enter your password'
},
{
type : 'length[6]',
prompt : 'Your password must be at least 6 characters'
}
]
}
},
inline: true,
onFailure: this.handleInvalidForm.bind(this),
onSuccess: this.handleValidForm.bind(this)
});
}
login() {
// Make call to auth service which will redirect on success or throw an error here if it fails
}
handleInvalidForm(e) {
this.setState({errors : e});
return false;
}
handleValidForm(e) {
e.preventDefault();
this.login();
}
render() {
return (
<form className="ui large form" >
<input type="text" valueLink={this.linkState('emailaddress')} name="emailaddress" placeholder="E-mail address"/>
<input type="password" valueLink={this.linkState('password')} name="password" placeholder="Password"/>
<div className="ui fluid big green submit button">Login</div>
</form>
)
ReactMixin(Login.prototype, React.addons.LinkedStateMixin);
Currently validation errors are set to occur inline. This means the plugin injects code into the DOM. This is not part of my state dictionary in React. Is this a problem?