react-hook-form 7.44.0-rc.1 → 7.44.0-rc.4

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.
@@ -44,12 +44,14 @@ function cloneObject(data) {
44
44
  else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
45
45
  (isArray || isObject(data))) {
46
46
  copy = isArray ? [] : {};
47
- if (!Array.isArray(data) && !isPlainObject(data)) {
47
+ if (!isArray && !isPlainObject(data)) {
48
48
  copy = data;
49
49
  }
50
50
  else {
51
51
  for (const key in data) {
52
- copy[key] = cloneObject(data[key]);
52
+ if (Object.hasOwn(data, key)) {
53
+ copy[key] = cloneObject(data[key]);
54
+ }
53
55
  }
54
56
  }
55
57
  }
@@ -405,6 +407,7 @@ function useController(props) {
405
407
  ...props.rules,
406
408
  value,
407
409
  }));
410
+ _registerProps.current = control.register(name, props.rules);
408
411
  React__default.useEffect(() => {
409
412
  const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
410
413
  const updateMounted = (name, value) => {
@@ -543,7 +546,7 @@ const POST_REQUEST = 'post';
543
546
  * <input {...register("name")} />
544
547
  * <p>{errors?.root?.server && 'Server error'}</p>
545
548
  * <button>Submit</button>
546
- * </form>
549
+ * </Form>
547
550
  * );
548
551
  * }
549
552
  * ```
@@ -551,49 +554,49 @@ const POST_REQUEST = 'post';
551
554
  function Form(props) {
552
555
  const methods = useFormContext();
553
556
  const [mounted, setMounted] = React.useState(false);
554
- const { control = methods.control, onSubmit, children, action, method = POST_REQUEST, headers, encType, onError, render, onSuccess, validateStatus, fetcher, ...rest } = props;
557
+ const { control = methods.control, onSubmit, children, action, method = POST_REQUEST, headers, encType, onError, render, onSuccess, validateStatus, ...rest } = props;
555
558
  const submit = async (event) => {
556
559
  let serverError = false;
557
- await control.handleSubmit(async (values) => {
560
+ await control.handleSubmit(async (data) => {
558
561
  const formData = new FormData();
559
562
  let formDataJson = '';
560
563
  try {
561
- formDataJson = JSON.stringify(values);
564
+ formDataJson = JSON.stringify(data);
562
565
  }
563
566
  catch (_a) { }
564
- control._names.mount.forEach((name) => formData.append(name, get(values, name)));
565
- onSubmit && onSubmit(values);
567
+ for (const name of control._names.mount) {
568
+ formData.append(name, get(data, name));
569
+ }
570
+ if (onSubmit) {
571
+ onSubmit({
572
+ data,
573
+ event,
574
+ action,
575
+ method,
576
+ formData,
577
+ formDataJson,
578
+ });
579
+ }
566
580
  if (action) {
567
581
  try {
568
- if (fetcher) {
569
- await fetcher(action, {
570
- method,
571
- values,
572
- event,
573
- formData,
574
- formDataJson,
575
- });
582
+ const shouldStringifySubmissionData = headers && headers['Content-Type'].includes('json');
583
+ const response = await fetch(action, {
584
+ method,
585
+ headers: {
586
+ ...headers,
587
+ ...(encType ? { 'Content-Type': encType } : {}),
588
+ },
589
+ body: shouldStringifySubmissionData ? formDataJson : formData,
590
+ });
591
+ if (response &&
592
+ (validateStatus
593
+ ? !validateStatus(response.status)
594
+ : response.status < 200 || response.status >= 300)) {
595
+ serverError = true;
596
+ onError && onError({ response });
576
597
  }
577
598
  else {
578
- const shouldStringifySubmissionData = headers && headers['Content-Type'].includes('json');
579
- const response = await fetch(action, {
580
- method,
581
- headers: {
582
- ...headers,
583
- ...(encType ? { 'Content-Type': encType } : {}),
584
- },
585
- body: shouldStringifySubmissionData ? formDataJson : formData,
586
- });
587
- if (response &&
588
- (validateStatus
589
- ? !validateStatus(response.status)
590
- : response.status < 200 || response.status >= 300)) {
591
- serverError = true;
592
- onError && onError({ response });
593
- }
594
- else {
595
- onSuccess && onSuccess({ response });
596
- }
599
+ onSuccess && onSuccess({ response });
597
600
  }
598
601
  }
599
602
  catch (error) {
@@ -876,7 +879,7 @@ var validateField = async (field, formValues, validateAllFieldCriteria, shouldUs
876
879
  }
877
880
  }
878
881
  }
879
- if (pattern && !isEmpty && isString(inputValue)) {
882
+ if (pattern && isString(inputValue)) {
880
883
  const { value: patternValue, message } = getValueAndMessage(pattern);
881
884
  if (isRegex(patternValue) && !inputValue.match(patternValue)) {
882
885
  error[name] = {
@@ -995,7 +998,7 @@ function baseGet(object, updatePath) {
995
998
  }
996
999
  function isEmptyArray(obj) {
997
1000
  for (const key in obj) {
998
- if (!isUndefined(obj[key])) {
1001
+ if (Object.hasOwn(obj, key) && !isUndefined(obj[key])) {
999
1002
  return false;
1000
1003
  }
1001
1004
  }
@@ -2029,7 +2032,7 @@ function createFormControl(props = {}, flushRootRender) {
2029
2032
  : updateValidAndValue(name, true, options.value);
2030
2033
  return {
2031
2034
  ...(disabledIsDefined ? { disabled: options.disabled } : {}),
2032
- ...(_options.shouldUseNativeValidation || _options.progressive
2035
+ ...(_options.progressive
2033
2036
  ? {
2034
2037
  required: !!options.required,
2035
2038
  min: getRuleValue(options.min),