react-hook-form 7.72.0 → 7.72.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAaV,WAAW,EAiBX,YAAY,EAIZ,aAAa,EAWd,MAAM,UAAU,CAAC;AAsDlB,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EAEjC,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAM,GACnE,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,CAAC;CACH,CAslDA"}
1
+ {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAaV,WAAW,EAiBX,YAAY,EAIZ,aAAa,EAWd,MAAM,UAAU,CAAC;AAsDlB,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EAEjC,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAM,GACnE,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,CAAC;CACH,CAkmDA"}
@@ -1 +1 @@
1
- {"version":3,"file":"isNameInFieldArray.d.ts","sourceRoot":"","sources":["../../src/logic/isNameInFieldArray.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;yBAIlC,OAAO,GAAG,CAAC,iBAAiB,CAAC,EAAE,MAAM,iBAAiB;AAAtE,wBACqC"}
1
+ {"version":3,"file":"isNameInFieldArray.d.ts","sourceRoot":"","sources":["../../src/logic/isNameInFieldArray.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;yBAElC,OAAO,GAAG,CAAC,iBAAiB,CAAC,EAAE,MAAM,iBAAiB;AAAtE,wBAMM"}
@@ -133,8 +133,8 @@ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
133
133
  if (key !== 'ref') {
134
134
  const val2 = object2[key];
135
135
  if ((isDateObject(val1) && isDateObject(val2)) ||
136
- (isObject(val1) && isObject(val2)) ||
137
- (Array.isArray(val1) && Array.isArray(val2))
136
+ ((isObject(val1) || Array.isArray(val1)) &&
137
+ (isObject(val2) || Array.isArray(val2)))
138
138
  ? !deepEqual(val1, val2, _internal_visited)
139
139
  : !Object.is(val1, val2)) {
140
140
  return false;
@@ -460,7 +460,9 @@ var hasValidation = (options) => options.mount &&
460
460
  options.pattern ||
461
461
  options.validate);
462
462
 
463
- var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
463
+ var isNameInFieldArray = (names, name) => name
464
+ .split('.')
465
+ .some((part, index, arr) => !isNaN(Number(part)) && names.has(arr.slice(0, index).join('.')));
464
466
 
465
467
  var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
466
468
  (_names.watchAll ||
@@ -817,6 +819,7 @@ function createFormControl(props = {}) {
817
819
  unMount: new Set(),
818
820
  array: new Set(),
819
821
  watch: new Set(),
822
+ registerName: new Set(),
820
823
  };
821
824
  let delayErrorCallback;
822
825
  let timer = 0;
@@ -890,6 +893,11 @@ function createFormControl(props = {}) {
890
893
  });
891
894
  }
892
895
  };
896
+ const _updateDirtyFields = (name) => {
897
+ const fullDirtyFields = getDirtyFields(_defaultValues, _formValues);
898
+ const rootName = getNodeParentName(name);
899
+ set(_formState.dirtyFields, rootName, get(fullDirtyFields, rootName));
900
+ };
893
901
  const _setFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
894
902
  if (args && method && !_options.disabled) {
895
903
  _state.action = true;
@@ -911,9 +919,7 @@ function createFormControl(props = {}) {
911
919
  shouldSetValues && set(_formState.touchedFields, name, touchedFields);
912
920
  }
913
921
  if (_proxyFormState.dirtyFields || _proxySubscribeFormState.dirtyFields) {
914
- const fullDirtyFields = getDirtyFields(_defaultValues, _formValues);
915
- const rootName = getNodeParentName(name);
916
- set(_formState.dirtyFields, rootName, get(fullDirtyFields, rootName));
922
+ _updateDirtyFields(name);
917
923
  }
918
924
  _subjects.state.next({
919
925
  name,
@@ -1242,9 +1248,10 @@ function createFormControl(props = {}) {
1242
1248
  _proxySubscribeFormState.isDirty ||
1243
1249
  _proxySubscribeFormState.dirtyFields) &&
1244
1250
  options.shouldDirty) {
1251
+ _updateDirtyFields(name);
1245
1252
  _subjects.state.next({
1246
1253
  name,
1247
- dirtyFields: getDirtyFields(_defaultValues, _formValues),
1254
+ dirtyFields: _formState.dirtyFields,
1248
1255
  isDirty: _getDirty(name, cloneValue),
1249
1256
  });
1250
1257
  }
@@ -1554,6 +1561,7 @@ function createFormControl(props = {}) {
1554
1561
  const register = (name, options = {}) => {
1555
1562
  let field = get(_fields, name);
1556
1563
  const disabledIsDefined = isBoolean(options.disabled) || isBoolean(_options.disabled);
1564
+ const shouldRevalidateRemount = !_names.registerName.has(name) && field && !field._f.mount;
1557
1565
  set(_fields, name, {
1558
1566
  ...(field || {}),
1559
1567
  _f: {
@@ -1564,7 +1572,7 @@ function createFormControl(props = {}) {
1564
1572
  },
1565
1573
  });
1566
1574
  _names.mount.add(name);
1567
- if (field) {
1575
+ if (field && !shouldRevalidateRemount) {
1568
1576
  _setDisabledField({
1569
1577
  disabled: isBoolean(options.disabled)
1570
1578
  ? options.disabled
@@ -1594,7 +1602,9 @@ function createFormControl(props = {}) {
1594
1602
  onBlur: onChange,
1595
1603
  ref: (ref) => {
1596
1604
  if (ref) {
1605
+ _names.registerName.add(name);
1597
1606
  register(name, options);
1607
+ _names.registerName.delete(name);
1598
1608
  field = get(_fields, name);
1599
1609
  const fieldRef = isUndefined(ref.value)
1600
1610
  ? ref.querySelectorAll
@@ -1807,6 +1817,7 @@ function createFormControl(props = {}) {
1807
1817
  mount: keepStateOptions.keepDirtyValues ? _names.mount : new Set(),
1808
1818
  unMount: new Set(),
1809
1819
  array: new Set(),
1820
+ registerName: new Set(),
1810
1821
  disabled: new Set(),
1811
1822
  watch: new Set(),
1812
1823
  watchAll: false,