From d8c8dd809ceacef108d779679c0860d7eb8adf90 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Tue, 24 Jan 2017 17:43:10 -0800 Subject: [PATCH] fix(auth) Dont allow invalid form submission with Enter key --- .../onboarding/lib/decorators/create-page-for-form.jsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal_packages/onboarding/lib/decorators/create-page-for-form.jsx b/internal_packages/onboarding/lib/decorators/create-page-for-form.jsx index 326016981..9a0297abf 100644 --- a/internal_packages/onboarding/lib/decorators/create-page-for-form.jsx +++ b/internal_packages/onboarding/lib/decorators/create-page-for-form.jsx @@ -55,6 +55,11 @@ const CreatePageForForm = (FormComponent) => { inputs[0].focus(); } + _isValid() { + const {populated, errorFieldNames} = this.state + return errorFieldNames.length === 0 && populated + } + onFieldChange = (event) => { const changes = {}; if (event.target.type === 'checkbox') { @@ -75,6 +80,7 @@ const CreatePageForForm = (FormComponent) => { } onFieldKeyPress = (event) => { + if (!this._isValid()) { return } if (['Enter', 'Return'].includes(event.key)) { this.onSubmit(); } @@ -130,7 +136,7 @@ const CreatePageForForm = (FormComponent) => { } _renderButton() { - const {accountInfo, submitting, errorFieldNames, populated} = this.state; + const {accountInfo, submitting} = this.state; const buttonLabel = FormComponent.submitLabel(accountInfo); // We're not on the last page. @@ -143,7 +149,7 @@ const CreatePageForForm = (FormComponent) => { ); } - if (errorFieldNames.length || !populated) { + if (!this._isValid()) { return ( );