@vuehookform/core 0.5.0 → 0.6.0

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.
@@ -539,14 +539,15 @@ function clearFieldTouched(touchedFields, fieldName) {
539
539
  }
540
540
  function clearFieldErrors(errors, fieldName) {
541
541
  const currentErrors = errors.value;
542
- const keys = Object.keys(currentErrors);
543
- if (keys.length === 0) return;
542
+ if (Object.keys(currentErrors).length === 0) return;
543
+ const nestedError = get(currentErrors, fieldName);
544
544
  const prefix = `${fieldName}.`;
545
- const keysToDelete = [];
546
- for (const key of keys) if (key === fieldName || key.startsWith(prefix)) keysToDelete.push(key);
547
- if (keysToDelete.length === 0) return;
545
+ const flatKeysToDelete = [];
546
+ for (const key of Object.keys(currentErrors)) if (key === fieldName || key.startsWith(prefix)) flatKeysToDelete.push(key);
547
+ if (nestedError === void 0 && flatKeysToDelete.length === 0) return;
548
548
  const newErrors = { ...currentErrors };
549
- for (const key of keysToDelete) delete newErrors[key];
549
+ for (const key of flatKeysToDelete) delete newErrors[key];
550
+ if (nestedError !== void 0) unset(newErrors, fieldName);
550
551
  errors.value = newErrors;
551
552
  }
552
553
  function updateFieldDirtyState(dirtyFields, defaultValues, defaultValueHashes, fieldName, currentValue) {
@@ -590,7 +591,6 @@ function createFieldError(errors, criteriaMode = "firstError") {
590
591
  const firstError = errors[0];
591
592
  if (!firstError) return "";
592
593
  if (criteriaMode === "firstError") return firstError.message;
593
- if (errors.length === 1) return firstError.message;
594
594
  const types = {};
595
595
  for (const err of errors) {
596
596
  const existing = types[err.type];
@@ -843,13 +843,13 @@ function createFieldRegistration(ctx, validate) {
843
843
  const error = await fieldOpts.validate(value);
844
844
  if (requestId !== ctx.validationRequestIds.get(fieldName)) return;
845
845
  if (ctx.resetGeneration.value !== resetGenAtStart) return;
846
- if (error) ctx.errors.value = {
847
- ...ctx.errors.value,
848
- [fieldName]: error
849
- };
850
- else {
846
+ if (error) {
851
847
  const newErrors = { ...ctx.errors.value };
852
- delete newErrors[fieldName];
848
+ set(newErrors, fieldName, error);
849
+ ctx.errors.value = newErrors;
850
+ } else {
851
+ const newErrors = { ...ctx.errors.value };
852
+ unset(newErrors, fieldName);
853
853
  ctx.errors.value = newErrors;
854
854
  }
855
855
  };
@@ -1527,7 +1527,7 @@ function useForm(options) {
1527
1527
  try {
1528
1528
  syncWithDebounce();
1529
1529
  if (await validate()) {
1530
- await onValid(ctx.formData);
1530
+ await onValid(deepClone(ctx.formData));
1531
1531
  ctx.isSubmitSuccessful.value = true;
1532
1532
  } else {
1533
1533
  onInvalid?.(formState.value.errors);
@@ -1609,7 +1609,6 @@ function useForm(options) {
1609
1609
  }
1610
1610
  }
1611
1611
  const opts = resetFieldOptions || {};
1612
- ctx.resetGeneration.value++;
1613
1612
  ctx.validationCache.delete(`${name}:partial`);
1614
1613
  ctx.validationCache.delete(`${name}:full`);
1615
1614
  const errorTimer = ctx.errorDelayTimers.get(name);
@@ -1618,6 +1617,11 @@ function useForm(options) {
1618
1617
  ctx.errorDelayTimers.delete(name);
1619
1618
  }
1620
1619
  ctx.pendingErrors.delete(name);
1620
+ const schemaTimer = ctx.schemaValidationTimers.get(name);
1621
+ if (schemaTimer) {
1622
+ clearTimeout(schemaTimer);
1623
+ ctx.schemaValidationTimers.delete(name);
1624
+ }
1621
1625
  let defaultValue = opts.defaultValue;
1622
1626
  if (defaultValue === void 0) defaultValue = get(ctx.defaultValues, name);
1623
1627
  else {
@@ -1730,13 +1734,13 @@ function useForm(options) {
1730
1734
  }
1731
1735
  }
1732
1736
  syncWithDebounce();
1733
- if (nameOrNames === void 0) return { ...ctx.formData };
1737
+ if (nameOrNames === void 0) return deepClone(ctx.formData);
1734
1738
  if (Array.isArray(nameOrNames)) {
1735
1739
  const result = {};
1736
- for (const fieldName of nameOrNames) result[fieldName] = get(ctx.formData, fieldName);
1740
+ for (const fieldName of nameOrNames) result[fieldName] = deepClone(get(ctx.formData, fieldName));
1737
1741
  return result;
1738
1742
  }
1739
- return get(ctx.formData, nameOrNames);
1743
+ return deepClone(get(ctx.formData, nameOrNames));
1740
1744
  }
1741
1745
  function getFieldState(name) {
1742
1746
  if (__DEV__) {
@@ -1770,11 +1774,7 @@ function useForm(options) {
1770
1774
  }
1771
1775
  if (options$1?.markAsSubmitted) ctx.submitCount.value++;
1772
1776
  if (name === void 0) return await validate();
1773
- if (Array.isArray(name)) {
1774
- let allValid = true;
1775
- for (const fieldName of name) if (!await validate(fieldName)) allValid = false;
1776
- return allValid;
1777
- }
1777
+ if (Array.isArray(name)) return (await Promise.all(name.map((fieldName) => validate(fieldName)))).every((isValid) => isValid);
1778
1778
  return await validate(name);
1779
1779
  }
1780
1780
  const setFocusWrapper = (name) => setFocus(name);
@@ -1907,3 +1907,5 @@ function isFieldError(error) {
1907
1907
  return typeof error === "object" && error !== null && "type" in error && "message" in error && typeof error.type === "string" && typeof error.message === "string";
1908
1908
  }
1909
1909
  export { FormContextKey, clearPathCache, get, isFieldError, provideForm, set, unset, useController, useForm, useFormContext, useFormState, useWatch };
1910
+
1911
+ //# sourceMappingURL=vuehookform.js.map