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

Function resetField

src/logic/createFormControl.ts:1460–1490  ·  view source on GitHub ↗
(name, options = {})

Source from the content-addressed store, hash-verified

1458 };
1459
1460 const resetField: UseFormResetField<TFieldValues> = (name, options = {}) => {
1461 if (get(_fields, name)) {
1462 if (isUndefined(options.defaultValue)) {
1463 setValue(name, cloneObject(get(_defaultValues, name)));
1464 } else {
1465 setValue(
1466 name,
1467 options.defaultValue as Parameters<typeof setValue<typeof name>>[1],
1468 );
1469 set(_defaultValues, name, cloneObject(options.defaultValue));
1470 }
1471
1472 if (!options.keepTouched) {
1473 unset(_formState.touchedFields, name);
1474 }
1475
1476 if (!options.keepDirty) {
1477 unset(_formState.dirtyFields, name);
1478 _formState.isDirty = options.defaultValue
1479 ? _getDirty(name, cloneObject(get(_defaultValues, name)))
1480 : _getDirty();
1481 }
1482
1483 if (!options.keepError) {
1484 unset(_formState.errors, name);
1485 _proxyFormState.isValid && _setValid();
1486 }
1487
1488 _subjects.state.next({ ..._formState });
1489 }
1490 };
1491
1492 const _reset: UseFormReset<TFieldValues> = (
1493 formValues,

Callers 2

AppFunction · 0.85
AppFunction · 0.85

Calls 5

setValueFunction · 0.85
cloneObjectFunction · 0.85
unsetFunction · 0.85
_getDirtyFunction · 0.85
_setValidFunction · 0.85

Tested by 2

AppFunction · 0.68
AppFunction · 0.68