Skip to content

Commit

Permalink
Fixes issue where password form field would not validate due to the s…
Browse files Browse the repository at this point in the history
…tate not being set yet. (#34247)
  • Loading branch information
roundhill authored Jun 25, 2019
1 parent f845a62 commit 765a767
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions client/blocks/signup-form/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,20 +324,32 @@ class SignupForm extends Component {
};

handleBlur = event => {
const data = this.getUserData();
const fieldId = event.target.id;
// Ensure that username and password field validation does not trigger prematurely
if ( fieldId === 'password' ) {
this.setState( { focusPassword: true } );
this.setState( { focusPassword: true }, () => {
this.validateAndSaveForm();
} );
return;
}
if ( fieldId === 'username' ) {
this.setState( { focusUsername: true } );
this.setState( { focusUsername: true }, () => {
this.validateAndSaveForm();
} );
return;
}

this.validateAndSaveForm();
};

validateAndSaveForm = () => {
const data = this.getUserData();
// When a user moves away from the signup form without having entered
// anything do not show error messages, think going to click log in.
if ( data.username.length === 0 && data.password.length === 0 && data.email.length === 0 ) {
return;
}

this.formStateController.sanitize();
this.formStateController.validate();
this.props.save && this.props.save( this.state.form );
Expand Down

0 comments on commit 765a767

Please sign in to comment.