react-hook-form 7.51.4 → 7.51.5

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.
@@ -78,6 +78,36 @@ var get = (object, path, defaultValue) => {
78
78
 
79
79
  var isBoolean = (value) => typeof value === 'boolean';
80
80
 
81
+ var isKey = (value) => /^\w*$/.test(value);
82
+
83
+ var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
84
+
85
+ var set = (object, path, value) => {
86
+ let index = -1;
87
+ const tempPath = isKey(path) ? [path] : stringToPath(path);
88
+ const length = tempPath.length;
89
+ const lastIndex = length - 1;
90
+ while (++index < length) {
91
+ const key = tempPath[index];
92
+ let newValue = value;
93
+ if (index !== lastIndex) {
94
+ const objValue = object[key];
95
+ newValue =
96
+ isObject(objValue) || Array.isArray(objValue)
97
+ ? objValue
98
+ : !isNaN(+tempPath[index + 1])
99
+ ? []
100
+ : {};
101
+ }
102
+ if (key === '__proto__') {
103
+ return;
104
+ }
105
+ object[key] = newValue;
106
+ object = object[key];
107
+ }
108
+ return object;
109
+ };
110
+
81
111
  const EVENTS = {
82
112
  BLUR: 'blur',
83
113
  FOCUS_OUT: 'focusout',
@@ -340,33 +370,6 @@ function useWatch(props) {
340
370
  return value;
341
371
  }
342
372
 
343
- var isKey = (value) => /^\w*$/.test(value);
344
-
345
- var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
346
-
347
- var set = (object, path, value) => {
348
- let index = -1;
349
- const tempPath = isKey(path) ? [path] : stringToPath(path);
350
- const length = tempPath.length;
351
- const lastIndex = length - 1;
352
- while (++index < length) {
353
- const key = tempPath[index];
354
- let newValue = value;
355
- if (index !== lastIndex) {
356
- const objValue = object[key];
357
- newValue =
358
- isObject(objValue) || Array.isArray(objValue)
359
- ? objValue
360
- : !isNaN(+tempPath[index + 1])
361
- ? []
362
- : {};
363
- }
364
- object[key] = newValue;
365
- object = object[key];
366
- }
367
- return object;
368
- };
369
-
370
373
  /**
371
374
  * Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
372
375
  *
@@ -2049,7 +2052,11 @@ function createFormControl(props = {}) {
2049
2052
  };
2050
2053
  const setError = (name, error, options) => {
2051
2054
  const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
2055
+ const currentError = get(_formState.errors, name) || {};
2056
+ // Don't override existing error messages elsewhere in the object tree.
2057
+ const { ref: currentRef, message, type, ...restOfErrorTree } = currentError;
2052
2058
  set(_formState.errors, name, {
2059
+ ...restOfErrorTree,
2053
2060
  ...error,
2054
2061
  ref,
2055
2062
  });
@@ -2092,7 +2099,7 @@ function createFormControl(props = {}) {
2092
2099
  !options.keepIsValid && _updateValid();
2093
2100
  };
2094
2101
  const _updateDisabledField = ({ disabled, name, field, fields, value, }) => {
2095
- if (isBoolean(disabled)) {
2102
+ if ((isBoolean(disabled) && _state.mount) || !!disabled) {
2096
2103
  const inputValue = disabled
2097
2104
  ? undefined
2098
2105
  : isUndefined(value)
@@ -2192,12 +2199,15 @@ function createFormControl(props = {}) {
2192
2199
  if (isBoolean(disabled)) {
2193
2200
  _subjects.state.next({ disabled });
2194
2201
  iterateFieldsByAction(_fields, (ref, name) => {
2195
- let requiredDisabledState = disabled;
2196
2202
  const currentField = get(_fields, name);
2197
- if (currentField && isBoolean(currentField._f.disabled)) {
2198
- requiredDisabledState || (requiredDisabledState = currentField._f.disabled);
2203
+ if (currentField) {
2204
+ ref.disabled = currentField._f.disabled || disabled;
2205
+ if (Array.isArray(currentField._f.refs)) {
2206
+ currentField._f.refs.forEach((inputRef) => {
2207
+ inputRef.disabled = currentField._f.disabled || disabled;
2208
+ });
2209
+ }
2199
2210
  }
2200
- ref.disabled = requiredDisabledState;
2201
2211
  }, 0, false);
2202
2212
  }
2203
2213
  };