1
I was trying to do that when the users pressed the button of Ubmit, it checked what the user entered, and if it was not valid it sent an error message through the span.Note:I cut the code to make it easier to read, but the problem ta in this part.
import React from 'react';
export class FormSignUp extends React.Component{
constructor(){
super();
this.state = {
firstName: '',
lastName: '',
email: '',
password: '',
rePassword: '',
day:'default',
month: 'default',
year: 'default',
gender:'1'
};
}
changeInp = e =>{
this.setState({
[e.target.name]: e.target.value
});
};
errors = {
nameError: ''
}
onSubmit = (e) => {
e.preventDefault();
if(this.state.firstName.length < 3){
this.errors.nameError = 'ta errado isso dai';
}
alert('submit');
console.log(this.state);
}
render(){
return(
<div className='formSignUp'>
<div className='fullSameInputS'>
<form>
<div className='nameDiv halfInput'>
<input type="text" name='firstName' value={this.state.firstName} onChange={e => this.changeInp(e)} className='signUpFstNameInput' placeholder='Nome'/>
<span>{this.errors.nameError}</span>
</div>
thanks man, it worked!!!!
– Vinnicius Pereira