MCPcopy Create free account
hub / github.com/react-hook-form/react-hook-form / onChange

Function onChange

src/logic/createFormControl.ts:845–999  ·  view source on GitHub ↗
(event)

Source from the content-addressed store, hash-verified

843 };
844
845 const onChange: ChangeHandler = async (event) => {
846 _state.mount = true;
847 const target = event.target;
848 let name: string = target.name;
849 let isFieldValueUpdated = true;
850 const field: Field = get(_fields, name);
851 const _updateIsFieldValueUpdated = (fieldValue: unknown) => {
852 isFieldValueUpdated =
853 Number.isNaN(fieldValue) ||
854 (isDateObject(fieldValue) && isNaN(fieldValue.getTime())) ||
855 deepEqual(fieldValue, get(_formValues, name, fieldValue));
856 };
857 const validationModeBeforeSubmit = getValidationModes(_options.mode);
858 const validationModeAfterSubmit = getValidationModes(
859 _options.reValidateMode,
860 );
861
862 if (field) {
863 let error;
864 let isValid;
865 const fieldValue = target.type
866 ? getFieldValue(field._f)
867 : getEventValue(event);
868 const isBlurEvent =
869 event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
870 const shouldSkipValidation =
871 (!hasValidation(field._f) &&
872 !props.validate &&
873 !_options.resolver &&
874 !get(_formState.errors, name) &&
875 !field._f.deps) ||
876 skipValidation(
877 isBlurEvent,
878 get(_formState.touchedFields, name),
879 _formState.isSubmitted,
880 validationModeAfterSubmit,
881 validationModeBeforeSubmit,
882 );
883 const watched = isWatched(name, _names, isBlurEvent);
884
885 set(_formValues, name, fieldValue);
886
887 if (isBlurEvent) {
888 if (!target || !target.readOnly) {
889 field._f.onBlur && field._f.onBlur(event);
890 delayErrorCallback && delayErrorCallback(0);
891 }
892 } else if (field._f.onChange) {
893 field._f.onChange(event);
894 }
895
896 const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent);
897
898 const shouldRender = !isEmptyObject(fieldState) || watched;
899
900 !isBlurEvent &&
901 _subjects.state.next({
902 name,

Callers 12

ComponentFunction · 0.85
InputFunction · 0.85
ComponentFunction · 0.85
CheckboxesFunction · 0.85
MuiCurrencyFormatFunction · 0.85
CustomMaskedInputFunction · 0.85
handleChangeFunction · 0.85
AppFunction · 0.85
MuiCurrencyFormatFunction · 0.85
CustomMaskedInputFunction · 0.85
handleChangeFunction · 0.85
AppFunction · 0.85

Calls 12

getFieldValueFunction · 0.85
updateTouchAndDirtyFunction · 0.85
cloneObjectFunction · 0.85
_setValidFunction · 0.85
validateFormFunction · 0.85
_runSchemaFunction · 0.85
_updateIsValidatingFunction · 0.85
schemaErrorLookupFunction · 0.85
executeBuiltInValidationFunction · 0.85
triggerFunction · 0.85
shouldRenderByErrorFunction · 0.85

Tested by 4

ComponentFunction · 0.68
InputFunction · 0.68
ComponentFunction · 0.68
CheckboxesFunction · 0.68