Skip to content

Commit

Permalink
Merge pull request Expensify#24347 from joh42/revert/21838
Browse files Browse the repository at this point in the history
[NO QA] revert changes from PRs 23306/23780
  • Loading branch information
techievivek authored Aug 10, 2023
2 parents d6a14d7 + 9cf039a commit 8d84c23
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
2 changes: 1 addition & 1 deletion contributingGuides/FORMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
14 changes: 1 addition & 13 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8d84c23

Please sign in to comment.