(event)
| 985 | }; |
| 986 | |
| 987 | const onChange: ChangeHandler = async (event) => { |
| 988 | _state.mount = true; |
| 989 | const target = event.target; |
| 990 | let name: string = target.name; |
| 991 | let isFieldValueUpdated = true; |
| 992 | const field: Field = get(_fields, name); |
| 993 | const _updateIsFieldValueUpdated = (fieldValue: unknown) => { |
| 994 | isFieldValueUpdated = |
| 995 | Number.isNaN(fieldValue) || |
| 996 | (isDateObject(fieldValue) && isNaN(fieldValue.getTime())) || |
| 997 | deepEqual(fieldValue, get(_formValues, name, fieldValue)); |
| 998 | }; |
| 999 | |
| 1000 | if (field) { |
| 1001 | let error; |
| 1002 | let isValid; |
| 1003 | const fieldValue = target.type |
| 1004 | ? getFieldValue(field._f) |
| 1005 | : getEventValue(event); |
| 1006 | const isBlurEvent = |
| 1007 | event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT; |
| 1008 | const hasNoValidationEffect = |
| 1009 | !hasValidation(field._f) && |
| 1010 | !props.validate && |
| 1011 | !_options.resolver && |
| 1012 | !get(_formState.errors, name) && |
| 1013 | !field._f.deps; |
| 1014 | const shouldSkipValidation = |
| 1015 | hasNoValidationEffect || |
| 1016 | skipValidation( |
| 1017 | isBlurEvent, |
| 1018 | get(_formState.touchedFields, name), |
| 1019 | _formState.isSubmitted, |
| 1020 | _validationModeAfterSubmit, |
| 1021 | _validationModeBeforeSubmit, |
| 1022 | ); |
| 1023 | const watched = isWatched(name, _names, isBlurEvent); |
| 1024 | |
| 1025 | set(_formValues, name, fieldValue); |
| 1026 | |
| 1027 | if (isBlurEvent) { |
| 1028 | if (!target || !target.readOnly) { |
| 1029 | field._f.onBlur && field._f.onBlur(event); |
| 1030 | delayErrorCallback && delayErrorCallback(0); |
| 1031 | } |
| 1032 | } else if (field._f.onChange) { |
| 1033 | field._f.onChange(event); |
| 1034 | } |
| 1035 | |
| 1036 | const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent); |
| 1037 | |
| 1038 | const shouldRender = !isEmptyObject(fieldState) || watched; |
| 1039 | |
| 1040 | !isBlurEvent && |
| 1041 | _subjects.state.next({ |
| 1042 | name, |
| 1043 | type: event.type, |
| 1044 | ...(_valuesSubscriberCount |
searching dependent graphs…