Don't allow enter to submit if field invalid

This commit is contained in:
David Baker 2018-11-21 18:02:58 +00:00
parent 6fe2c9c2bb
commit 08e2ba8c6c

View file

@ -122,7 +122,7 @@ export default React.createClass({
}, },
_onPassPhraseKeyPress: function(e) { _onPassPhraseKeyPress: function(e) {
if (e.key === 'Enter') { if (e.key === 'Enter' && this._passPhraseIsValid()) {
this._onPassPhraseNextClick(); this._onPassPhraseNextClick();
} }
}, },
@ -136,7 +136,7 @@ export default React.createClass({
}, },
_onPassPhraseConfirmKeyPress: function(e) { _onPassPhraseConfirmKeyPress: function(e) {
if (e.key === 'Enter') { if (e.key === 'Enter' && this.state.passPhrase === this.state.passPhraseConfirm) {
this._onPassPhraseConfirmNextClick(); this._onPassPhraseConfirmNextClick();
} }
}, },
@ -167,6 +167,10 @@ export default React.createClass({
}); });
}, },
_passPhraseIsValid: function() {
return this.state.passPhrase !== '';
},
_renderPhasePassPhrase: function() { _renderPhasePassPhrase: function() {
const DialogButtons = sdk.getComponent('views.elements.DialogButtons'); const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
@ -187,7 +191,7 @@ export default React.createClass({
<DialogButtons primaryButton={_t('Next')} <DialogButtons primaryButton={_t('Next')}
onPrimaryButtonClick={this._onPassPhraseNextClick} onPrimaryButtonClick={this._onPassPhraseNextClick}
hasCancel={false} hasCancel={false}
disabled={this.state.passPhrase === ''} disabled={!this._passPhraseIsValid()}
/> />
<p>{_t( <p>{_t(