@vuehookform/core 0.4.6 → 0.4.7

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.
@@ -839,6 +839,7 @@ function createFieldRegistration(ctx, validate) {
839
839
  let handlers = ctx.fieldHandlers.get(name);
840
840
  if (!handlers) {
841
841
  const runCustomValidation = async (fieldName, value, requestId, resetGenAtStart) => {
842
+ if (!ctx.fieldRefs.has(fieldName)) return;
842
843
  const fieldOpts = ctx.fieldOptions.get(fieldName);
843
844
  if (!fieldOpts?.validate || fieldOpts.disabled) return;
844
845
  const error = await fieldOpts.validate(value);
@@ -1071,7 +1072,7 @@ function createFieldArrayManager(ctx, validate, setFocus) {
1071
1072
  if (!focusOptions?.shouldFocus) return;
1072
1073
  await (0, vue.nextTick)();
1073
1074
  const focusItemOffset = focusOptions?.focusIndex ?? 0;
1074
- let fieldPath = `${name}.${baseIndex + Math.min(focusItemOffset, addedCount - 1)}`;
1075
+ let fieldPath = `${name}.${baseIndex + Math.max(0, Math.min(focusItemOffset, addedCount - 1))}`;
1075
1076
  if (focusOptions?.focusName) fieldPath = `${fieldPath}.${focusOptions.focusName}`;
1076
1077
  setFocus(fieldPath);
1077
1078
  };
@@ -1242,13 +1243,10 @@ function createFieldArrayManager(ctx, validate, setFocus) {
1242
1243
  set(ctx.formData, name, newValues);
1243
1244
  const newItems = [...fa.items.value];
1244
1245
  const itemA = newItems[indexA];
1245
- const itemB = newItems[indexB];
1246
- if (itemA && itemB) {
1247
- newItems[indexA] = itemB;
1248
- newItems[indexB] = itemA;
1249
- fa.items.value = newItems;
1250
- swapInCache(indexA, indexB);
1251
- }
1246
+ newItems[indexA] = newItems[indexB];
1247
+ newItems[indexB] = itemA;
1248
+ fa.items.value = newItems;
1249
+ swapInCache(indexA, indexB);
1252
1250
  updateFieldDirtyState(ctx.dirtyFields, ctx.defaultValues, ctx.defaultValueHashes, name, get(ctx.formData, name));
1253
1251
  validateIfNeeded();
1254
1252
  return true;
@@ -1268,16 +1266,14 @@ function createFieldArrayManager(ctx, validate, setFocus) {
1268
1266
  }
1269
1267
  const newItems = [...fa.items.value];
1270
1268
  const [removedItem] = newItems.splice(from, 1);
1271
- if (removedItem) {
1272
- newItems.splice(to, 0, removedItem);
1273
- fa.items.value = newItems;
1274
- const minIdx = Math.min(from, to);
1275
- const maxIdx = Math.max(from, to);
1276
- const items = fa.items.value;
1277
- for (let i = minIdx; i <= maxIdx; i++) {
1278
- const item = items[i];
1279
- if (item) indexCache.set(item.key, i);
1280
- }
1269
+ newItems.splice(to, 0, removedItem);
1270
+ fa.items.value = newItems;
1271
+ const minIdx = Math.min(from, to);
1272
+ const maxIdx = Math.max(from, to);
1273
+ const items = fa.items.value;
1274
+ for (let i = minIdx; i <= maxIdx; i++) {
1275
+ const item = items[i];
1276
+ if (item) indexCache.set(item.key, i);
1281
1277
  }
1282
1278
  updateFieldDirtyState(ctx.dirtyFields, ctx.defaultValues, ctx.defaultValueHashes, name, get(ctx.formData, name));
1283
1279
  validateIfNeeded();
@@ -1529,6 +1525,7 @@ function useForm(options) {
1529
1525
  Object.assign(ctx.formData, newValues);
1530
1526
  if (!opts.keepErrors) {
1531
1527
  ctx.errors.value = {};
1528
+ ctx.externalErrors.value = {};
1532
1529
  ctx.persistentErrorFields.clear();
1533
1530
  }
1534
1531
  if (!opts.keepTouched) ctx.touchedFields.value = {};
@@ -1629,7 +1626,8 @@ function useForm(options) {
1629
1626
  for (const field of fieldsToClean) {
1630
1627
  clearFieldErrors(ctx.errors, field);
1631
1628
  clearFieldErrors(ctx.externalErrors, field);
1632
- ctx.persistentErrorFields.delete(field);
1629
+ const prefix = `${field}.`;
1630
+ for (const persistentField of ctx.persistentErrorFields) if (persistentField === field || persistentField.startsWith(prefix)) ctx.persistentErrorFields.delete(persistentField);
1633
1631
  }
1634
1632
  }
1635
1633
  function setError(name, error) {
@@ -837,6 +837,7 @@ function createFieldRegistration(ctx, validate) {
837
837
  let handlers = ctx.fieldHandlers.get(name);
838
838
  if (!handlers) {
839
839
  const runCustomValidation = async (fieldName, value, requestId, resetGenAtStart) => {
840
+ if (!ctx.fieldRefs.has(fieldName)) return;
840
841
  const fieldOpts = ctx.fieldOptions.get(fieldName);
841
842
  if (!fieldOpts?.validate || fieldOpts.disabled) return;
842
843
  const error = await fieldOpts.validate(value);
@@ -1069,7 +1070,7 @@ function createFieldArrayManager(ctx, validate, setFocus) {
1069
1070
  if (!focusOptions?.shouldFocus) return;
1070
1071
  await nextTick();
1071
1072
  const focusItemOffset = focusOptions?.focusIndex ?? 0;
1072
- let fieldPath = `${name}.${baseIndex + Math.min(focusItemOffset, addedCount - 1)}`;
1073
+ let fieldPath = `${name}.${baseIndex + Math.max(0, Math.min(focusItemOffset, addedCount - 1))}`;
1073
1074
  if (focusOptions?.focusName) fieldPath = `${fieldPath}.${focusOptions.focusName}`;
1074
1075
  setFocus(fieldPath);
1075
1076
  };
@@ -1240,13 +1241,10 @@ function createFieldArrayManager(ctx, validate, setFocus) {
1240
1241
  set(ctx.formData, name, newValues);
1241
1242
  const newItems = [...fa.items.value];
1242
1243
  const itemA = newItems[indexA];
1243
- const itemB = newItems[indexB];
1244
- if (itemA && itemB) {
1245
- newItems[indexA] = itemB;
1246
- newItems[indexB] = itemA;
1247
- fa.items.value = newItems;
1248
- swapInCache(indexA, indexB);
1249
- }
1244
+ newItems[indexA] = newItems[indexB];
1245
+ newItems[indexB] = itemA;
1246
+ fa.items.value = newItems;
1247
+ swapInCache(indexA, indexB);
1250
1248
  updateFieldDirtyState(ctx.dirtyFields, ctx.defaultValues, ctx.defaultValueHashes, name, get(ctx.formData, name));
1251
1249
  validateIfNeeded();
1252
1250
  return true;
@@ -1266,16 +1264,14 @@ function createFieldArrayManager(ctx, validate, setFocus) {
1266
1264
  }
1267
1265
  const newItems = [...fa.items.value];
1268
1266
  const [removedItem] = newItems.splice(from, 1);
1269
- if (removedItem) {
1270
- newItems.splice(to, 0, removedItem);
1271
- fa.items.value = newItems;
1272
- const minIdx = Math.min(from, to);
1273
- const maxIdx = Math.max(from, to);
1274
- const items = fa.items.value;
1275
- for (let i = minIdx; i <= maxIdx; i++) {
1276
- const item = items[i];
1277
- if (item) indexCache.set(item.key, i);
1278
- }
1267
+ newItems.splice(to, 0, removedItem);
1268
+ fa.items.value = newItems;
1269
+ const minIdx = Math.min(from, to);
1270
+ const maxIdx = Math.max(from, to);
1271
+ const items = fa.items.value;
1272
+ for (let i = minIdx; i <= maxIdx; i++) {
1273
+ const item = items[i];
1274
+ if (item) indexCache.set(item.key, i);
1279
1275
  }
1280
1276
  updateFieldDirtyState(ctx.dirtyFields, ctx.defaultValues, ctx.defaultValueHashes, name, get(ctx.formData, name));
1281
1277
  validateIfNeeded();
@@ -1527,6 +1523,7 @@ function useForm(options) {
1527
1523
  Object.assign(ctx.formData, newValues);
1528
1524
  if (!opts.keepErrors) {
1529
1525
  ctx.errors.value = {};
1526
+ ctx.externalErrors.value = {};
1530
1527
  ctx.persistentErrorFields.clear();
1531
1528
  }
1532
1529
  if (!opts.keepTouched) ctx.touchedFields.value = {};
@@ -1627,7 +1624,8 @@ function useForm(options) {
1627
1624
  for (const field of fieldsToClean) {
1628
1625
  clearFieldErrors(ctx.errors, field);
1629
1626
  clearFieldErrors(ctx.externalErrors, field);
1630
- ctx.persistentErrorFields.delete(field);
1627
+ const prefix = `${field}.`;
1628
+ for (const persistentField of ctx.persistentErrorFields) if (persistentField === field || persistentField.startsWith(prefix)) ctx.persistentErrorFields.delete(persistentField);
1631
1629
  }
1632
1630
  }
1633
1631
  function setError(name, error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuehookform/core",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "TypeScript-first form library for Vue 3, inspired by React Hook Form. Form-level state management with Zod validation.",
5
5
  "type": "module",
6
6
  "workspaces": [