0
I made a simple validation using react
, and would like the 'b' message only to be available when the user clicked on submit
how can I do?
export default class LoginApp extends React.Component {
validarEmail=(e)=>{
e.preventDefault();
const email = e.target.elements.email.value;
const password = e.target.elements.password.value.length;
const emailValid = validator.isEmail(email)
if(emailValid === false){
console.log('email incorreto, favor verificar')
}else if(password < 8 ){
console.log('senha é muito curta, favor informar uma de maior numero de caracteres')
}else{
console.log('email e senha corretos')
}
}
render() {
return (
<div>
<Header />
<div className="container-app">
<form method="get" name="modal_form" onSubmit={this.validarEmail}>
<div className="form-group">
<label>Email address</label><br/>
<input className="form-control" name="email"
/>
{!!this.validarEmail.emailValid ? <p>a</p>:<p>b</p>}
</div>
<div className="form-group">
<label>Password</label><br/>
<input className="form-control" name="password"
/>
{!!this.validarEmail.password < 8 ? <p>a</p>:<p>b</p>}
</div>
<button type="submit" className="button" >Submit</button>
</form>
</div>
</div>
);
}
}