From 9cf039a2120f2ad1ed24ddef7c2ed3df49d92ea8 Mon Sep 17 00:00:00 2001 From: Johannes Idarsson <138504087+joh42@users.noreply.github.com> Date: Thu, 10 Aug 2023 00:31:28 +0200 Subject: [PATCH] removed changes from PRs 23306/23780 --- contributingGuides/FORMS.md | 2 +- src/components/Form.js | 14 +------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/contributingGuides/FORMS.md b/contributingGuides/FORMS.md index 673d0de938dd..01f145dafbc6 100644 --- a/contributingGuides/FORMS.md +++ b/contributingGuides/FORMS.md @@ -100,7 +100,7 @@ Form inputs will NOT store draft values by default. This is to avoid accidentall ### Validate on Blur, on Change and Submit -Each individual form field that requires validation will have its own validate test defined. When the form field loses focus (blur) we will run that validate test and show feedback. A blur on one field will not cause other fields to validate or show errors unless they have already been blurred. To prevent server errors from being cleared inadvertently, we only run validation on blur if any form data has changed since the last validation/submit. +Each individual form field that requires validation will have its own validate test defined. When the form field loses focus (blur) we will run that validate test and show feedback. A blur on one field will not cause other fields to validate or show errors unless they have already been blurred. Once a user has “touched” an input, i.e. blurred the input, we will also start validating that input on change when the user goes back to editing it. diff --git a/src/components/Form.js b/src/components/Form.js index af776ce9d0f7..d4db912d975a 100644 --- a/src/components/Form.js +++ b/src/components/Form.js @@ -102,7 +102,6 @@ function Form(props) { const inputRefs = useRef({}); const touchedInputs = useRef({}); const isFirstRender = useRef(true); - const lastValidatedValues = useRef({...props.draftValues}); const {validate, onSubmit, children} = props; @@ -148,11 +147,6 @@ function Form(props) { setErrors(touchedInputErrors); } - const isAtLeastOneInputTouched = _.keys(touchedInputs.current).length > 0; - if (isAtLeastOneInputTouched) { - lastValidatedValues.current = values; - } - return touchedInputErrors; }, [errors, touchedInputs, props.formID, validate], @@ -312,12 +306,7 @@ function Form(props) { // web and mobile web platforms. setTimeout(() => { setTouchedInput(inputID); - - // To prevent server errors from being cleared inadvertently, we only run validation on blur if any form values have changed since the last validation/submit - const shouldValidate = !_.isEqual(inputValues, lastValidatedValues.current); - if (shouldValidate) { - onValidate(inputValues); - } + onValidate(inputValues); }, 200); } @@ -429,7 +418,6 @@ function Form(props) { delete inputRefs.current[inputID]; delete touchedInputs.current[inputID]; - delete lastValidatedValues.current[inputID]; setInputValues((prevState) => { const copyPrevState = _.clone(prevState);