Folks,
Am trying to only show the Button
when the 2 form fields match. What am I missing in the logic? Current behavior is not predictable, and shows the button at random.
Kindly pardon the newb question, little front-end experience (if none at all)
Thanks!
class ResetPassword extends React.Component {
constructor(props) {
super(props);
this.state = {};
this.handleNewPasswordChange = this.handleNewPasswordChange.bind(this);
this.handleConfirmPasswordChange = this.handleConfirmPasswordChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.checkPasswordMatch = this.checkPasswordMatch.bind(this);
}
handleNewPasswordChange(event) {
this.setState({newPassword: event.target.value});
this.checkPasswordMatch();
}
handleConfirmPasswordChange(event) {
this.setState({confirmPassword: event.target.value});
this.checkPasswordMatch();
}
checkPasswordMatch() {
if (this.state.newPassword === this.state.confirmPassword && this.state.newPassword.length > 4) {
this.setState({passwordsMatch: true});
} else {
this.setState({passwordsMatch: false});
}
}
render() {
return (
<Container>
<h1>
Password Reset
</h1>
<div className="login-box">
<form onSubmit={this.handleSubmit}>
<label>
{strings.NewPassword} :
<input
id="newPassword"
name="newPassword"
type="password"
value={this.state.newPassword}
onChange={this.handleNewPasswordChange} />
</label>
<label>
{strings.ConfirmPassword} :
<input
id="confirmPassword"
name="confirmPassword"
type="password"
value={this.state.confirmPassword}
onChange={this.handleConfirmPasswordChange} />
</label>
{ this.state.passwordsMatch ? <Button>{strings.ChangePassword}</Button> : null }
</form>
</div>
</Container>
)
}
}