From eafd7e12d05ce6fbe4ee502351460b290f21242a Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 30 Jan 2019 10:50:51 -0600 Subject: [PATCH] Validate login phone number on blur --- src/components/structures/auth/Login.js | 19 +++++++++++++------ src/components/views/auth/PasswordLogin.js | 7 +++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/components/structures/auth/Login.js b/src/components/structures/auth/Login.js index 51f05c3a4d..91d8001e72 100644 --- a/src/components/structures/auth/Login.js +++ b/src/components/structures/auth/Login.js @@ -284,16 +284,22 @@ module.exports = React.createClass({ }, onPhoneNumberChanged: function(phoneNumber) { - // Validate the phone number entered - if (!PHONE_NUMBER_REGEX.test(phoneNumber)) { - this.setState({ errorText: _t('The phone number entered looks invalid') }); - return; - } - this.setState({ phoneNumber: phoneNumber, + }); + }, + + onPhoneNumberBlur: function(phoneNumber) { + this.setState({ errorText: null, }); + + // Validate the phone number entered + if (!PHONE_NUMBER_REGEX.test(phoneNumber)) { + this.setState({ + errorText: _t('The phone number entered looks invalid'), + }); + } }, onServerConfigChange: function(config) { @@ -648,6 +654,7 @@ module.exports = React.createClass({ onUsernameBlur={this.onUsernameBlur} onPhoneCountryChanged={this.onPhoneCountryChanged} onPhoneNumberChanged={this.onPhoneNumberChanged} + onPhoneNumberBlur={this.onPhoneNumberBlur} onForgotPasswordClick={this.props.onForgotPasswordClick} loginIncorrect={this.state.loginIncorrect} hsUrl={this.state.enteredHomeserverUrl} diff --git a/src/components/views/auth/PasswordLogin.js b/src/components/views/auth/PasswordLogin.js index f692c31b35..0dbf52a4b9 100644 --- a/src/components/views/auth/PasswordLogin.js +++ b/src/components/views/auth/PasswordLogin.js @@ -35,6 +35,7 @@ class PasswordLogin extends React.Component { onPasswordChanged: function() {}, onPhoneCountryChanged: function() {}, onPhoneNumberChanged: function() {}, + onPhoneNumberBlur: function() {}, initialUsername: "", initialPhoneCountry: "", initialPhoneNumber: "", @@ -60,6 +61,7 @@ class PasswordLogin extends React.Component { this.onLoginTypeChange = this.onLoginTypeChange.bind(this); this.onPhoneCountryChanged = this.onPhoneCountryChanged.bind(this); this.onPhoneNumberChanged = this.onPhoneNumberChanged.bind(this); + this.onPhoneNumberBlur = this.onPhoneNumberBlur.bind(this); this.onPasswordChanged = this.onPasswordChanged.bind(this); this.isLoginEmpty = this.isLoginEmpty.bind(this); } @@ -153,6 +155,10 @@ class PasswordLogin extends React.Component { this.props.onPhoneNumberChanged(ev.target.value); } + onPhoneNumberBlur(ev) { + this.props.onPhoneNumberBlur(ev.target.value); + } + onPasswordChanged(ev) { this.setState({password: ev.target.value}); this.props.onPasswordChanged(ev.target.value); @@ -214,6 +220,7 @@ class PasswordLogin extends React.Component { type="text" name="phoneNumber" onChange={this.onPhoneNumberChanged} + onBlur={this.onPhoneNumberBlur} placeholder={_t("Mobile phone number")} value={this.state.phoneNumber} autoFocus