Answer the question
In order to leave comments, you need to log in
How to display an error when confirming a password?
I can not implement password confirmation during registration. To write an error, below the password confirmation field, a phrase like the password does not match
Implementation example
import React, { Component } from 'react';
import Input, { InputLabel, InputAdornment } from 'material-ui/Input';
import { FormControl, FormHelperText } from 'material-ui/Form';
import TextField from 'material-ui/TextField';
import { Link } from 'react-router-dom';
import Button from 'material-ui/Button';
export default class Registration extends Component{
constructor(props){
super(props);
this.state = {
login: '',
password: '',
confirmPassword: '',
email: '',
errors: ''
};
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange = this.handleChange.bind(this);
}
...
handleSubmit(e){
e.preventDefault();
if (this.state.password === this.state.confirmPassword){
console.log(true);
} else {
console.log(false);
this.state.errors = 'Пароль не совпадает'
}
console.log(this.state);
}
render(){
return(
<div className='registration'>
<h1>Регистарация</h1>
<form onSubmit={this.handleSubmit}>
...
{this.state.errors ? this.state.errors : ''}
...
</form>
</div>
)
}
}
Answer the question
In order to leave comments, you need to log in
Instead of this.state.errors = "Password does not match"; - this.setState({ errors: 'Password doesn't match' })
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question