Skip to content

Commit

Permalink
Merge pull request #26699 from tamdao/26009-validation-message-not-show
Browse files Browse the repository at this point in the history
Checking ToS box before filling fields throws error in mweb but not in android app
  • Loading branch information
puneetlath authored Sep 8, 2023
2 parents 05883f0 + 0508ec8 commit 6e106c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions contributingGuides/FORMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ Form.js will automatically provide the following props to any input with the inp
- onBlur: An onBlur handler that calls validate.
- onTouched: An onTouched handler that marks the input as touched.
- onInputChange: An onChange handler that saves draft values and calls validate for that input (inputA). Passing an inputID as a second param allows inputA to manipulate the input value of the provided inputID (inputB).
- onFocus: An onFocus handler that marks the input as focused.

## Dynamic Form Inputs

Expand Down
12 changes: 12 additions & 0 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function Form(props) {
const formContentRef = useRef(null);
const inputRefs = useRef({});
const touchedInputs = useRef({});
const focusedInput = useRef(null);
const isFirstRender = useRef(true);

const {validate, onSubmit, children} = props;
Expand Down Expand Up @@ -305,6 +306,12 @@ function Form(props) {
// as this is already happening by the value prop.
defaultValue: undefined,
errorText: errors[inputID] || fieldErrorMessage,
onFocus: (event) => {
focusedInput.current = inputID;
if (_.isFunction(child.props.onFocus)) {
child.props.onFocus(event);
}
},
onBlur: (event) => {
// Only run validation when user proactively blurs the input.
if (Visibility.isVisible() && Visibility.hasFocus()) {
Expand All @@ -328,6 +335,11 @@ function Form(props) {
},
onInputChange: (value, key) => {
const inputKey = key || inputID;

if (focusedInput.current && focusedInput.current !== inputKey) {
setTouchedInput(focusedInput.current);
}

setInputValues((prevState) => {
const newState = {
...prevState,
Expand Down

0 comments on commit 6e106c6

Please sign in to comment.