@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.
@@ -541,14 +541,15 @@ function clearFieldTouched(touchedFields, fieldName) {
541
541
  }
542
542
  function clearFieldErrors(errors, fieldName) {
543
543
  const currentErrors = errors.value;
544
- const keys = Object.keys(currentErrors);
545
- if (keys.length === 0) return;
544
+ if (Object.keys(currentErrors).length === 0) return;
545
+ const nestedError = get(currentErrors, fieldName);
546
546
  const prefix = `${fieldName}.`;
547
- const keysToDelete = [];
548
- for (const key of keys) if (key === fieldName || key.startsWith(prefix)) keysToDelete.push(key);
549
- if (keysToDelete.length === 0) return;
547
+ const flatKeysToDelete = [];
548
+ for (const key of Object.keys(currentErrors)) if (key === fieldName || key.startsWith(prefix)) flatKeysToDelete.push(key);
549
+ if (nestedError === void 0 && flatKeysToDelete.length === 0) return;
550
550
  const newErrors = { ...currentErrors };
551
- for (const key of keysToDelete) delete newErrors[key];
551
+ for (const key of flatKeysToDelete) delete newErrors[key];
552
+ if (nestedError !== void 0) unset(newErrors, fieldName);
552
553
  errors.value = newErrors;
553
554
  }
554
555
  function updateFieldDirtyState(dirtyFields, defaultValues, defaultValueHashes, fieldName, currentValue) {
@@ -592,7 +593,6 @@ function createFieldError(errors, criteriaMode = "firstError") {
592
593
  const firstError = errors[0];
593
594
  if (!firstError) return "";
594
595
  if (criteriaMode === "firstError") return firstError.message;
595
- if (errors.length === 1) return firstError.message;
596
596
  const types = {};
597
597
  for (const err of errors) {
598
598
  const existing = types[err.type];
@@ -845,13 +845,13 @@ function createFieldRegistration(ctx, validate) {
845
845
  const error = await fieldOpts.validate(value);
846
846
  if (requestId !== ctx.validationRequestIds.get(fieldName)) return;
847
847
  if (ctx.resetGeneration.value !== resetGenAtStart) return;
848
- if (error) ctx.errors.value = {
849
- ...ctx.errors.value,
850
- [fieldName]: error
851
- };
852
- else {
848
+ if (error) {
853
849
  const newErrors = { ...ctx.errors.value };
854
- delete newErrors[fieldName];
850
+ set(newErrors, fieldName, error);
851
+ ctx.errors.value = newErrors;
852
+ } else {
853
+ const newErrors = { ...ctx.errors.value };
854
+ unset(newErrors, fieldName);
855
855
  ctx.errors.value = newErrors;
856
856
  }
857
857
  };
@@ -1529,7 +1529,7 @@ function useForm(options) {
1529
1529
  try {
1530
1530
  syncWithDebounce();
1531
1531
  if (await validate()) {
1532
- await onValid(ctx.formData);
1532
+ await onValid(deepClone(ctx.formData));
1533
1533
  ctx.isSubmitSuccessful.value = true;
1534
1534
  } else {
1535
1535
  onInvalid?.(formState.value.errors);
@@ -1611,7 +1611,6 @@ function useForm(options) {
1611
1611
  }
1612
1612
  }
1613
1613
  const opts = resetFieldOptions || {};
1614
- ctx.resetGeneration.value++;
1615
1614
  ctx.validationCache.delete(`${name}:partial`);
1616
1615
  ctx.validationCache.delete(`${name}:full`);
1617
1616
  const errorTimer = ctx.errorDelayTimers.get(name);
@@ -1620,6 +1619,11 @@ function useForm(options) {
1620
1619
  ctx.errorDelayTimers.delete(name);
1621
1620
  }
1622
1621
  ctx.pendingErrors.delete(name);
1622
+ const schemaTimer = ctx.schemaValidationTimers.get(name);
1623
+ if (schemaTimer) {
1624
+ clearTimeout(schemaTimer);
1625
+ ctx.schemaValidationTimers.delete(name);
1626
+ }
1623
1627
  let defaultValue = opts.defaultValue;
1624
1628
  if (defaultValue === void 0) defaultValue = get(ctx.defaultValues, name);
1625
1629
  else {
@@ -1732,13 +1736,13 @@ function useForm(options) {
1732
1736
  }
1733
1737
  }
1734
1738
  syncWithDebounce();
1735
- if (nameOrNames === void 0) return { ...ctx.formData };
1739
+ if (nameOrNames === void 0) return deepClone(ctx.formData);
1736
1740
  if (Array.isArray(nameOrNames)) {
1737
1741
  const result = {};
1738
- for (const fieldName of nameOrNames) result[fieldName] = get(ctx.formData, fieldName);
1742
+ for (const fieldName of nameOrNames) result[fieldName] = deepClone(get(ctx.formData, fieldName));
1739
1743
  return result;
1740
1744
  }
1741
- return get(ctx.formData, nameOrNames);
1745
+ return deepClone(get(ctx.formData, nameOrNames));
1742
1746
  }
1743
1747
  function getFieldState(name) {
1744
1748
  if (__DEV__) {
@@ -1772,11 +1776,7 @@ function useForm(options) {
1772
1776
  }
1773
1777
  if (options$1?.markAsSubmitted) ctx.submitCount.value++;
1774
1778
  if (name === void 0) return await validate();
1775
- if (Array.isArray(name)) {
1776
- let allValid = true;
1777
- for (const fieldName of name) if (!await validate(fieldName)) allValid = false;
1778
- return allValid;
1779
- }
1779
+ if (Array.isArray(name)) return (await Promise.all(name.map((fieldName) => validate(fieldName)))).every((isValid) => isValid);
1780
1780
  return await validate(name);
1781
1781
  }
1782
1782
  const setFocusWrapper = (name) => setFocus(name);
@@ -1920,3 +1920,5 @@ exports.useForm = useForm;
1920
1920
  exports.useFormContext = useFormContext;
1921
1921
  exports.useFormState = useFormState;
1922
1922
  exports.useWatch = useWatch;
1923
+
1924
+ //# sourceMappingURL=vuehookform.cjs.map