vee-validate 4.15.1 → 5.0.0-beta.1
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.
- package/README.md +4 -4
- package/dist/vee-validate.cjs +97 -164
- package/dist/vee-validate.d.ts +21 -71
- package/dist/vee-validate.iife.js +97 -164
- package/dist/vee-validate.iife.prod.js.mjs +3 -3
- package/dist/vee-validate.mjs +107 -168
- package/package.json +3 -1
package/dist/vee-validate.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* vee-validate
|
|
3
|
-
* (c)
|
|
2
|
+
* vee-validate v5.0.0-beta.1
|
|
3
|
+
* (c) 2026 Abdelrahman Awad
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
import { getCurrentInstance, inject, warn as warn$1, computed, toValue, ref, watch, nextTick, unref, isRef, reactive, onUnmounted, onMounted, provide, onBeforeUnmount, defineComponent, toRef, resolveDynamicComponent, h, readonly, watchEffect, shallowRef } from 'vue';
|
|
@@ -162,11 +162,8 @@ const isClient = typeof window !== 'undefined';
|
|
|
162
162
|
function isLocator(value) {
|
|
163
163
|
return isCallable(value) && !!value.__locatorRef;
|
|
164
164
|
}
|
|
165
|
-
function
|
|
166
|
-
return
|
|
167
|
-
}
|
|
168
|
-
function isYupValidator(value) {
|
|
169
|
-
return !!value && isCallable(value.validate);
|
|
165
|
+
function isStandardSchema(value) {
|
|
166
|
+
return isObject(value) && '~standard' in value;
|
|
170
167
|
}
|
|
171
168
|
function hasCheckedAttr(type) {
|
|
172
169
|
return type === 'checkbox' || type === 'radio';
|
|
@@ -346,6 +343,27 @@ function isFile(a) {
|
|
|
346
343
|
return a instanceof File;
|
|
347
344
|
}
|
|
348
345
|
|
|
346
|
+
// src/getDotPath/getDotPath.ts
|
|
347
|
+
function getDotPath(issue) {
|
|
348
|
+
if (issue.path?.length) {
|
|
349
|
+
let dotPath = "";
|
|
350
|
+
for (const item of issue.path) {
|
|
351
|
+
const key = typeof item === "object" ? item.key : item;
|
|
352
|
+
if (typeof key === "string" || typeof key === "number") {
|
|
353
|
+
if (dotPath) {
|
|
354
|
+
dotPath += `.${key}`;
|
|
355
|
+
} else {
|
|
356
|
+
dotPath += key;
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return dotPath;
|
|
363
|
+
}
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
|
|
349
367
|
function cleanupNonNestedPath(path) {
|
|
350
368
|
if (isNotNestedPath(path)) {
|
|
351
369
|
return path.replace(/\[|\]/gi, '');
|
|
@@ -586,6 +604,31 @@ function debounceNextTick(inner) {
|
|
|
586
604
|
return new Promise(resolve => resolves.push(resolve));
|
|
587
605
|
};
|
|
588
606
|
}
|
|
607
|
+
function _combineIssueItems(items, getPath) {
|
|
608
|
+
const issueMap = {};
|
|
609
|
+
for (const item of items) {
|
|
610
|
+
const path = getPath(item);
|
|
611
|
+
if (!issueMap[path]) {
|
|
612
|
+
issueMap[path] = {
|
|
613
|
+
path,
|
|
614
|
+
messages: [],
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
if ('messages' in item) {
|
|
618
|
+
issueMap[path].messages.push(...item.messages);
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
issueMap[path].messages.push(item.message);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return Object.values(issueMap);
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Aggregates standard schema issues by path.
|
|
628
|
+
*/
|
|
629
|
+
function combineStandardIssues(issues) {
|
|
630
|
+
return _combineIssueItems(issues, issue => { var _a; return (issue.path ? (_a = getDotPath(issue)) !== null && _a !== void 0 ? _a : '' : ''); });
|
|
631
|
+
}
|
|
589
632
|
|
|
590
633
|
function normalizeChildren(tag, context, slotProps) {
|
|
591
634
|
if (!context.slots.default) {
|
|
@@ -617,9 +660,6 @@ function hasValueBinding(el) {
|
|
|
617
660
|
}
|
|
618
661
|
|
|
619
662
|
function parseInputValue(el) {
|
|
620
|
-
if (el.type === 'number') {
|
|
621
|
-
return Number.isNaN(el.valueAsNumber) ? el.value : el.valueAsNumber;
|
|
622
|
-
}
|
|
623
663
|
if (el.type === 'range') {
|
|
624
664
|
return Number.isNaN(el.valueAsNumber) ? el.value : el.valueAsNumber;
|
|
625
665
|
}
|
|
@@ -792,8 +832,8 @@ async function validate(value, rules, options = {}) {
|
|
|
792
832
|
*/
|
|
793
833
|
async function _validate(field, value) {
|
|
794
834
|
const rules = field.rules;
|
|
795
|
-
if (
|
|
796
|
-
return
|
|
835
|
+
if (isStandardSchema(rules)) {
|
|
836
|
+
return validateFieldWithStandardSchema(value, Object.assign(Object.assign({}, field), { rules }));
|
|
797
837
|
}
|
|
798
838
|
// if a generic function or chain of generic functions
|
|
799
839
|
if (isCallable(rules) || Array.isArray(rules)) {
|
|
@@ -855,58 +895,24 @@ async function _validate(field, value) {
|
|
|
855
895
|
errors,
|
|
856
896
|
};
|
|
857
897
|
}
|
|
858
|
-
function isYupError(err) {
|
|
859
|
-
return !!err && err.name === 'ValidationError';
|
|
860
|
-
}
|
|
861
|
-
function yupToTypedSchema(yupSchema) {
|
|
862
|
-
const schema = {
|
|
863
|
-
__type: 'VVTypedSchema',
|
|
864
|
-
async parse(values, context) {
|
|
865
|
-
var _a;
|
|
866
|
-
try {
|
|
867
|
-
const output = await yupSchema.validate(values, { abortEarly: false, context: (context === null || context === void 0 ? void 0 : context.formData) || {} });
|
|
868
|
-
return {
|
|
869
|
-
output,
|
|
870
|
-
errors: [],
|
|
871
|
-
};
|
|
872
|
-
}
|
|
873
|
-
catch (err) {
|
|
874
|
-
// Yup errors have a name prop one them.
|
|
875
|
-
// https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string
|
|
876
|
-
if (!isYupError(err)) {
|
|
877
|
-
throw err;
|
|
878
|
-
}
|
|
879
|
-
if (!((_a = err.inner) === null || _a === void 0 ? void 0 : _a.length) && err.errors.length) {
|
|
880
|
-
return { errors: [{ path: err.path, errors: err.errors }] };
|
|
881
|
-
}
|
|
882
|
-
const errors = err.inner.reduce((acc, curr) => {
|
|
883
|
-
const path = curr.path || '';
|
|
884
|
-
if (!acc[path]) {
|
|
885
|
-
acc[path] = { errors: [], path };
|
|
886
|
-
}
|
|
887
|
-
acc[path].errors.push(...curr.errors);
|
|
888
|
-
return acc;
|
|
889
|
-
}, {});
|
|
890
|
-
return { errors: Object.values(errors) };
|
|
891
|
-
}
|
|
892
|
-
},
|
|
893
|
-
};
|
|
894
|
-
return schema;
|
|
895
|
-
}
|
|
896
898
|
/**
|
|
897
899
|
* Handles yup validation
|
|
898
900
|
*/
|
|
899
|
-
async function
|
|
900
|
-
const
|
|
901
|
-
|
|
901
|
+
async function validateFieldWithStandardSchema(value, context) {
|
|
902
|
+
const result = await context.rules['~standard'].validate(value);
|
|
903
|
+
if (!result.issues) {
|
|
904
|
+
return {
|
|
905
|
+
value: result.value,
|
|
906
|
+
errors: [],
|
|
907
|
+
};
|
|
908
|
+
}
|
|
902
909
|
const messages = [];
|
|
903
|
-
for (const error of result.
|
|
904
|
-
if (error.
|
|
905
|
-
messages.push(
|
|
910
|
+
for (const error of result.issues) {
|
|
911
|
+
if (error.message) {
|
|
912
|
+
messages.push(error.message);
|
|
906
913
|
}
|
|
907
914
|
}
|
|
908
915
|
return {
|
|
909
|
-
value: result.value,
|
|
910
916
|
errors: messages,
|
|
911
917
|
};
|
|
912
918
|
}
|
|
@@ -962,27 +968,33 @@ function fillTargetValues(params, crossTable) {
|
|
|
962
968
|
return acc;
|
|
963
969
|
}, {});
|
|
964
970
|
}
|
|
965
|
-
async function
|
|
966
|
-
const
|
|
967
|
-
const validationResult = await typedSchema.parse(klona(values), { formData: klona(values) });
|
|
971
|
+
async function validateStandardSchema(schema, values) {
|
|
972
|
+
const validationResult = await schema['~standard'].validate(klona(values));
|
|
968
973
|
const results = {};
|
|
969
974
|
const errors = {};
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
975
|
+
if (!validationResult.issues) {
|
|
976
|
+
return {
|
|
977
|
+
valid: true,
|
|
978
|
+
results: {},
|
|
979
|
+
errors: {},
|
|
980
|
+
values: validationResult.value,
|
|
981
|
+
source: 'schema',
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
const combinedIssues = combineStandardIssues(validationResult.issues || []);
|
|
985
|
+
for (const error of combinedIssues) {
|
|
986
|
+
const messages = error.messages;
|
|
987
|
+
const path = error.path;
|
|
976
988
|
results[path] = { valid: !messages.length, errors: messages };
|
|
977
989
|
if (messages.length) {
|
|
978
990
|
errors[path] = messages[0];
|
|
979
991
|
}
|
|
980
992
|
}
|
|
981
993
|
return {
|
|
982
|
-
valid: !
|
|
994
|
+
valid: !combinedIssues.length,
|
|
983
995
|
results,
|
|
984
996
|
errors,
|
|
985
|
-
values:
|
|
997
|
+
values: undefined,
|
|
986
998
|
source: 'schema',
|
|
987
999
|
};
|
|
988
1000
|
}
|
|
@@ -1027,7 +1039,7 @@ function useFieldState(path, init) {
|
|
|
1027
1039
|
if (!init.form) {
|
|
1028
1040
|
const { errors, setErrors } = createFieldErrors();
|
|
1029
1041
|
const id = ID_COUNTER >= Number.MAX_SAFE_INTEGER ? 0 : ++ID_COUNTER;
|
|
1030
|
-
const meta = createFieldMeta(value, initialValue, errors
|
|
1042
|
+
const meta = createFieldMeta(value, initialValue, errors);
|
|
1031
1043
|
function setState(state) {
|
|
1032
1044
|
var _a;
|
|
1033
1045
|
if ('value' in state) {
|
|
@@ -1059,7 +1071,6 @@ function useFieldState(path, init) {
|
|
|
1059
1071
|
label: init.label,
|
|
1060
1072
|
type: init.type,
|
|
1061
1073
|
validate: init.validate,
|
|
1062
|
-
schema: init.schema,
|
|
1063
1074
|
});
|
|
1064
1075
|
const errors = computed(() => state.errors);
|
|
1065
1076
|
function setState(state) {
|
|
@@ -1155,13 +1166,11 @@ function resolveModelValue(modelValue, form, initialValue, path) {
|
|
|
1155
1166
|
/**
|
|
1156
1167
|
* Creates meta flags state and some associated effects with them
|
|
1157
1168
|
*/
|
|
1158
|
-
function createFieldMeta(currentValue, initialValue, errors
|
|
1159
|
-
const isRequired = computed(() => { var _a, _b, _c; return (_c = (_b = (_a = toValue(schema)) === null || _a === void 0 ? void 0 : _a.describe) === null || _b === void 0 ? void 0 : _b.call(_a).required) !== null && _c !== void 0 ? _c : false; });
|
|
1169
|
+
function createFieldMeta(currentValue, initialValue, errors) {
|
|
1160
1170
|
const meta = reactive({
|
|
1161
1171
|
touched: false,
|
|
1162
1172
|
pending: false,
|
|
1163
1173
|
valid: true,
|
|
1164
|
-
required: isRequired,
|
|
1165
1174
|
validated: !!unref(errors).length,
|
|
1166
1175
|
initialValue: computed(() => unref(initialValue)),
|
|
1167
1176
|
dirty: computed(() => {
|
|
@@ -1220,7 +1229,7 @@ async function installDevtoolsPlugin(app) {
|
|
|
1220
1229
|
packageName: 'vee-validate',
|
|
1221
1230
|
homepage: 'https://vee-validate.logaretm.com/v4',
|
|
1222
1231
|
app,
|
|
1223
|
-
logo: 'https://vee-validate.logaretm.com/
|
|
1232
|
+
logo: 'https://vee-validate.logaretm.com/v5/logo.png',
|
|
1224
1233
|
}, api => {
|
|
1225
1234
|
API = api;
|
|
1226
1235
|
api.addInspector({
|
|
@@ -1329,6 +1338,9 @@ const refreshInspector = throttle(() => {
|
|
|
1329
1338
|
}, 100);
|
|
1330
1339
|
}, 100);
|
|
1331
1340
|
function registerFormWithDevTools(form) {
|
|
1341
|
+
if (!(process.env.NODE_ENV !== 'production') || !isClient) {
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1332
1344
|
const vm = getCurrentInstance();
|
|
1333
1345
|
if (!API) {
|
|
1334
1346
|
const app = vm === null || vm === void 0 ? void 0 : vm.appContext.app;
|
|
@@ -1346,6 +1358,9 @@ function registerFormWithDevTools(form) {
|
|
|
1346
1358
|
refreshInspector();
|
|
1347
1359
|
}
|
|
1348
1360
|
function registerSingleFieldWithDevtools(field) {
|
|
1361
|
+
if (!(process.env.NODE_ENV !== 'production') || !isClient) {
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1349
1364
|
const vm = getCurrentInstance();
|
|
1350
1365
|
if (!API) {
|
|
1351
1366
|
const app = vm === null || vm === void 0 ? void 0 : vm.appContext.app;
|
|
@@ -1370,7 +1385,7 @@ function mapFormForDevtoolsInspector(form) {
|
|
|
1370
1385
|
});
|
|
1371
1386
|
function buildFormTree(tree, path = []) {
|
|
1372
1387
|
const key = [...path].pop();
|
|
1373
|
-
if ('id' in tree) {
|
|
1388
|
+
if ('id' in tree && typeof tree.id === 'string') {
|
|
1374
1389
|
return Object.assign(Object.assign({}, tree), { label: key || tree.label });
|
|
1375
1390
|
}
|
|
1376
1391
|
if (isObject(tree)) {
|
|
@@ -1465,7 +1480,8 @@ function getFieldNodeTags(multiple, fieldsCount, type, valid, form) {
|
|
|
1465
1480
|
function encodeNodeId(form, stateOrField) {
|
|
1466
1481
|
const type = stateOrField ? ('path' in stateOrField ? 'pathState' : 'field') : 'form';
|
|
1467
1482
|
const fieldPath = stateOrField ? ('path' in stateOrField ? stateOrField === null || stateOrField === void 0 ? void 0 : stateOrField.path : toValue(stateOrField === null || stateOrField === void 0 ? void 0 : stateOrField.name)) : '';
|
|
1468
|
-
const
|
|
1483
|
+
const ff = type === 'field' ? stateOrField === null || stateOrField === void 0 ? void 0 : stateOrField.id : fieldPath;
|
|
1484
|
+
const idObject = { f: form === null || form === void 0 ? void 0 : form.formId, ff, type };
|
|
1469
1485
|
return btoa(encodeURIComponent(JSON.stringify(idObject)));
|
|
1470
1486
|
}
|
|
1471
1487
|
function decodeNodeId(nodeId) {
|
|
@@ -1604,15 +1620,11 @@ function _useField(path, rules, opts) {
|
|
|
1604
1620
|
return undefined;
|
|
1605
1621
|
}
|
|
1606
1622
|
const rulesValue = unref(rules);
|
|
1607
|
-
if (
|
|
1608
|
-
isTypedSchema(rulesValue) ||
|
|
1609
|
-
isCallable(rulesValue) ||
|
|
1610
|
-
Array.isArray(rulesValue)) {
|
|
1623
|
+
if (isStandardSchema(rulesValue) || isCallable(rulesValue) || Array.isArray(rulesValue)) {
|
|
1611
1624
|
return rulesValue;
|
|
1612
1625
|
}
|
|
1613
1626
|
return normalizeRules(rulesValue);
|
|
1614
1627
|
});
|
|
1615
|
-
const isTyped = !isCallable(validator.value) && isTypedSchema(toValue(rules));
|
|
1616
1628
|
const { id, value, initialValue, meta, setState, errors, flags } = useFieldState(name, {
|
|
1617
1629
|
modelValue,
|
|
1618
1630
|
form,
|
|
@@ -1620,7 +1632,6 @@ function _useField(path, rules, opts) {
|
|
|
1620
1632
|
label,
|
|
1621
1633
|
type,
|
|
1622
1634
|
validate: validator.value ? validate$1 : undefined,
|
|
1623
|
-
schema: isTyped ? rules : undefined,
|
|
1624
1635
|
});
|
|
1625
1636
|
const errorMessage = computed(() => errors.value[0]);
|
|
1626
1637
|
if (syncVModel) {
|
|
@@ -1781,12 +1792,8 @@ function _useField(path, rules, opts) {
|
|
|
1781
1792
|
// extract cross-field dependencies in a computed prop
|
|
1782
1793
|
const dependencies = computed(() => {
|
|
1783
1794
|
const rulesVal = validator.value;
|
|
1784
|
-
// is falsy, a function schema or a
|
|
1785
|
-
if (!rulesVal ||
|
|
1786
|
-
isCallable(rulesVal) ||
|
|
1787
|
-
isYupValidator(rulesVal) ||
|
|
1788
|
-
isTypedSchema(rulesVal) ||
|
|
1789
|
-
Array.isArray(rulesVal)) {
|
|
1795
|
+
// is falsy, a function schema or a standard schema
|
|
1796
|
+
if (!rulesVal || isCallable(rulesVal) || isStandardSchema(rulesVal) || Array.isArray(rulesVal)) {
|
|
1790
1797
|
return {};
|
|
1791
1798
|
}
|
|
1792
1799
|
return Object.keys(rulesVal).reduce((acc, rule) => {
|
|
@@ -1852,6 +1859,7 @@ function _useField(path, rules, opts) {
|
|
|
1852
1859
|
* Normalizes partial field options to include the full options
|
|
1853
1860
|
*/
|
|
1854
1861
|
function normalizeOptions(opts) {
|
|
1862
|
+
var _a;
|
|
1855
1863
|
const defaults = () => ({
|
|
1856
1864
|
initialValue: undefined,
|
|
1857
1865
|
validateOnMount: false,
|
|
@@ -1863,22 +1871,19 @@ function normalizeOptions(opts) {
|
|
|
1863
1871
|
controlled: true,
|
|
1864
1872
|
});
|
|
1865
1873
|
const isVModelSynced = !!(opts === null || opts === void 0 ? void 0 : opts.syncVModel);
|
|
1866
|
-
const modelPropName = typeof (opts === null || opts === void 0 ? void 0 : opts.syncVModel) === 'string' ? opts.syncVModel :
|
|
1874
|
+
const modelPropName = typeof (opts === null || opts === void 0 ? void 0 : opts.syncVModel) === 'string' ? opts.syncVModel : 'modelValue';
|
|
1867
1875
|
const initialValue = isVModelSynced && !('initialValue' in (opts || {}))
|
|
1868
1876
|
? getCurrentModelValue(getCurrentInstance(), modelPropName)
|
|
1869
1877
|
: opts === null || opts === void 0 ? void 0 : opts.initialValue;
|
|
1870
1878
|
if (!opts) {
|
|
1871
1879
|
return Object.assign(Object.assign({}, defaults()), { initialValue });
|
|
1872
1880
|
}
|
|
1873
|
-
|
|
1874
|
-
const
|
|
1875
|
-
|
|
1876
|
-
const syncVModel = (opts === null || opts === void 0 ? void 0 : opts.modelPropName) || (opts === null || opts === void 0 ? void 0 : opts.syncVModel) || false;
|
|
1877
|
-
return Object.assign(Object.assign(Object.assign({}, defaults()), (opts || {})), { initialValue, controlled: controlled !== null && controlled !== void 0 ? controlled : true, checkedValue,
|
|
1878
|
-
syncVModel });
|
|
1881
|
+
const controlled = (_a = opts.controlled) !== null && _a !== void 0 ? _a : true;
|
|
1882
|
+
const syncVModel = (opts === null || opts === void 0 ? void 0 : opts.syncVModel) || false;
|
|
1883
|
+
return Object.assign(Object.assign(Object.assign({}, defaults()), (opts || {})), { initialValue, controlled: controlled !== null && controlled !== void 0 ? controlled : true, checkedValue: opts === null || opts === void 0 ? void 0 : opts.checkedValue, syncVModel });
|
|
1879
1884
|
}
|
|
1880
1885
|
function useFieldWithChecked(name, rules, opts) {
|
|
1881
|
-
const form =
|
|
1886
|
+
const form = (opts === null || opts === void 0 ? void 0 : opts.controlled) ? injectWithSelf(FormContextKey) : undefined;
|
|
1882
1887
|
const checkedValue = opts === null || opts === void 0 ? void 0 : opts.checkedValue;
|
|
1883
1888
|
const uncheckedValue = opts === null || opts === void 0 ? void 0 : opts.uncheckedValue;
|
|
1884
1889
|
function patchCheckedApi(field) {
|
|
@@ -2016,9 +2021,9 @@ const FieldImpl = /** #__PURE__ */ defineComponent({
|
|
|
2016
2021
|
type: null,
|
|
2017
2022
|
default: undefined,
|
|
2018
2023
|
},
|
|
2019
|
-
|
|
2024
|
+
controlled: {
|
|
2020
2025
|
type: Boolean,
|
|
2021
|
-
default:
|
|
2026
|
+
default: true,
|
|
2022
2027
|
},
|
|
2023
2028
|
keepValue: {
|
|
2024
2029
|
type: Boolean,
|
|
@@ -2034,7 +2039,7 @@ const FieldImpl = /** #__PURE__ */ defineComponent({
|
|
|
2034
2039
|
const { errors, value, errorMessage, validate: validateField, handleChange, handleBlur, setTouched, resetField, handleReset, meta, checked, setErrors, setValue, } = useField(name, rules, {
|
|
2035
2040
|
validateOnMount: props.validateOnMount,
|
|
2036
2041
|
bails: props.bails,
|
|
2037
|
-
|
|
2042
|
+
controlled: props.controlled,
|
|
2038
2043
|
type: ctx.attrs.type,
|
|
2039
2044
|
initialValue: resolveInitialValue(props, ctx),
|
|
2040
2045
|
// Only for checkboxes and radio buttons
|
|
@@ -2165,10 +2170,6 @@ const PRIVATE_PATH_STATE_KEYS = ['bails', 'fieldsCount', 'id', 'multiple', 'type
|
|
|
2165
2170
|
function resolveInitialValues(opts) {
|
|
2166
2171
|
const givenInitial = (opts === null || opts === void 0 ? void 0 : opts.initialValues) || {};
|
|
2167
2172
|
const providedValues = Object.assign({}, toValue(givenInitial));
|
|
2168
|
-
const schema = unref(opts === null || opts === void 0 ? void 0 : opts.validationSchema);
|
|
2169
|
-
if (schema && isTypedSchema(schema) && isCallable(schema.cast)) {
|
|
2170
|
-
return klona(schema.cast(providedValues) || {});
|
|
2171
|
-
}
|
|
2172
2173
|
return klona(providedValues);
|
|
2173
2174
|
}
|
|
2174
2175
|
function useForm(opts) {
|
|
@@ -2303,19 +2304,6 @@ function useForm(opts) {
|
|
|
2303
2304
|
if (unsetBatchIndex !== -1) {
|
|
2304
2305
|
UNSET_BATCH.splice(unsetBatchIndex, 1);
|
|
2305
2306
|
}
|
|
2306
|
-
const isRequired = computed(() => {
|
|
2307
|
-
var _a, _b, _c, _d;
|
|
2308
|
-
const schemaValue = toValue(schema);
|
|
2309
|
-
if (isTypedSchema(schemaValue)) {
|
|
2310
|
-
return (_b = (_a = schemaValue.describe) === null || _a === void 0 ? void 0 : _a.call(schemaValue, toValue(path)).required) !== null && _b !== void 0 ? _b : false;
|
|
2311
|
-
}
|
|
2312
|
-
// Path own schema
|
|
2313
|
-
const configSchemaValue = toValue(config === null || config === void 0 ? void 0 : config.schema);
|
|
2314
|
-
if (isTypedSchema(configSchemaValue)) {
|
|
2315
|
-
return (_d = (_c = configSchemaValue.describe) === null || _c === void 0 ? void 0 : _c.call(configSchemaValue).required) !== null && _d !== void 0 ? _d : false;
|
|
2316
|
-
}
|
|
2317
|
-
return false;
|
|
2318
|
-
});
|
|
2319
2307
|
const id = FIELD_ID_COUNTER++;
|
|
2320
2308
|
const state = reactive({
|
|
2321
2309
|
id,
|
|
@@ -2324,7 +2312,6 @@ function useForm(opts) {
|
|
|
2324
2312
|
pending: false,
|
|
2325
2313
|
valid: true,
|
|
2326
2314
|
validated: !!((_a = initialErrors[pathValue]) === null || _a === void 0 ? void 0 : _a.length),
|
|
2327
|
-
required: isRequired,
|
|
2328
2315
|
initialValue,
|
|
2329
2316
|
errors: shallowRef([]),
|
|
2330
2317
|
bails: (_b = config === null || config === void 0 ? void 0 : config.bails) !== null && _b !== void 0 ? _b : false,
|
|
@@ -2599,9 +2586,6 @@ function useForm(opts) {
|
|
|
2599
2586
|
resetForm,
|
|
2600
2587
|
resetField,
|
|
2601
2588
|
handleSubmit,
|
|
2602
|
-
useFieldModel,
|
|
2603
|
-
defineInputBinds,
|
|
2604
|
-
defineComponentBinds: defineComponentBinds,
|
|
2605
2589
|
defineField,
|
|
2606
2590
|
stageInitialValue,
|
|
2607
2591
|
unsetInitialValue,
|
|
@@ -2737,7 +2721,6 @@ function useForm(opts) {
|
|
|
2737
2721
|
function resetForm(resetState, opts) {
|
|
2738
2722
|
let newValues = klona((resetState === null || resetState === void 0 ? void 0 : resetState.values) ? resetState.values : originalInitialValues.value);
|
|
2739
2723
|
newValues = (opts === null || opts === void 0 ? void 0 : opts.force) ? newValues : merge(originalInitialValues.value, newValues);
|
|
2740
|
-
newValues = isTypedSchema(schema) && isCallable(schema.cast) ? schema.cast(newValues) : newValues;
|
|
2741
2724
|
setInitialValues(newValues, { force: opts === null || opts === void 0 ? void 0 : opts.force });
|
|
2742
2725
|
mutateAllPathState(state => {
|
|
2743
2726
|
var _a;
|
|
@@ -2855,8 +2838,8 @@ function useForm(opts) {
|
|
|
2855
2838
|
return { valid: true, results: {}, errors: {}, source: 'none' };
|
|
2856
2839
|
}
|
|
2857
2840
|
isValidating.value = true;
|
|
2858
|
-
const formResult =
|
|
2859
|
-
? await
|
|
2841
|
+
const formResult = isStandardSchema(schemaValue)
|
|
2842
|
+
? await validateStandardSchema(schemaValue, formValues)
|
|
2860
2843
|
: await validateObjectSchema(schemaValue, formValues, {
|
|
2861
2844
|
names: fieldNames.value,
|
|
2862
2845
|
bailsMap: fieldBailsMap.value,
|
|
@@ -2949,50 +2932,6 @@ function useForm(opts) {
|
|
|
2949
2932
|
const model = createModel(path, () => { var _a, _b, _c; return (_c = (_a = evalConfig().validateOnModelUpdate) !== null && _a !== void 0 ? _a : (_b = getConfig()) === null || _b === void 0 ? void 0 : _b.validateOnModelUpdate) !== null && _c !== void 0 ? _c : true; });
|
|
2950
2933
|
return [model, props];
|
|
2951
2934
|
}
|
|
2952
|
-
function useFieldModel(pathOrPaths) {
|
|
2953
|
-
if (!Array.isArray(pathOrPaths)) {
|
|
2954
|
-
return createModel(pathOrPaths);
|
|
2955
|
-
}
|
|
2956
|
-
return pathOrPaths.map(p => createModel(p, true));
|
|
2957
|
-
}
|
|
2958
|
-
/**
|
|
2959
|
-
* @deprecated use defineField instead
|
|
2960
|
-
*/
|
|
2961
|
-
function defineInputBinds(path, config) {
|
|
2962
|
-
const [model, props] = defineField(path, config);
|
|
2963
|
-
function onBlur() {
|
|
2964
|
-
props.value.onBlur();
|
|
2965
|
-
}
|
|
2966
|
-
function onInput(e) {
|
|
2967
|
-
const value = normalizeEventValue(e);
|
|
2968
|
-
setFieldValue(toValue(path), value, false);
|
|
2969
|
-
props.value.onInput();
|
|
2970
|
-
}
|
|
2971
|
-
function onChange(e) {
|
|
2972
|
-
const value = normalizeEventValue(e);
|
|
2973
|
-
setFieldValue(toValue(path), value, false);
|
|
2974
|
-
props.value.onChange();
|
|
2975
|
-
}
|
|
2976
|
-
return computed(() => {
|
|
2977
|
-
return Object.assign(Object.assign({}, props.value), { onBlur,
|
|
2978
|
-
onInput,
|
|
2979
|
-
onChange, value: model.value });
|
|
2980
|
-
});
|
|
2981
|
-
}
|
|
2982
|
-
/**
|
|
2983
|
-
* @deprecated use defineField instead
|
|
2984
|
-
*/
|
|
2985
|
-
function defineComponentBinds(path, config) {
|
|
2986
|
-
const [model, props] = defineField(path, config);
|
|
2987
|
-
const pathState = findPathState(toValue(path));
|
|
2988
|
-
function onUpdateModelValue(value) {
|
|
2989
|
-
model.value = value;
|
|
2990
|
-
}
|
|
2991
|
-
return computed(() => {
|
|
2992
|
-
const conf = isCallable(config) ? config(omit(pathState, PRIVATE_PATH_STATE_KEYS)) : config || {};
|
|
2993
|
-
return Object.assign({ [conf.model || 'modelValue']: model.value, [`onUpdate:${conf.model || 'modelValue'}`]: onUpdateModelValue }, props.value);
|
|
2994
|
-
});
|
|
2995
|
-
}
|
|
2996
2935
|
const ctx = Object.assign(Object.assign({}, formCtx), { values: readonly(formValues), handleReset: () => resetForm(), submitForm });
|
|
2997
2936
|
provide(PublicFormContextKey, ctx);
|
|
2998
2937
|
return ctx;
|
|
@@ -3944,4 +3883,4 @@ function useSetFormValues() {
|
|
|
3944
3883
|
return setFormValues;
|
|
3945
3884
|
}
|
|
3946
3885
|
|
|
3947
|
-
export { ErrorMessage, Field, FieldArray, FieldContextKey, Form, FormContextKey, IS_ABSENT, PublicFormContextKey, cleanupNonNestedPath, configure, defineRule, isNotNestedPath, normalizeRules, useField, useFieldArray, useFieldError, useFieldValue, useForm, useFormContext, useFormErrors, useFormValues, useIsFieldDirty, useIsFieldTouched, useIsFieldValid, useIsFormDirty, useIsFormTouched, useIsFormValid, useIsSubmitting, useIsValidating, useResetForm, useSetFieldError, useSetFieldTouched, useSetFieldValue, useSetFormErrors, useSetFormTouched, useSetFormValues, useSubmitCount, useSubmitForm, useValidateField, useValidateForm, validate, validateObjectSchema as validateObject };
|
|
3886
|
+
export { ErrorMessage, Field, FieldArray, FieldContextKey, Form, FormContextKey, IS_ABSENT, PublicFormContextKey, cleanupNonNestedPath, configure, defineRule, getConfig, isNotNestedPath, normalizeRules, useField, useFieldArray, useFieldError, useFieldValue, useForm, useFormContext, useFormErrors, useFormValues, useIsFieldDirty, useIsFieldTouched, useIsFieldValid, useIsFormDirty, useIsFormTouched, useIsFormValid, useIsSubmitting, useIsValidating, useResetForm, useSetFieldError, useSetFieldTouched, useSetFieldValue, useSetFormErrors, useSetFormTouched, useSetFormValues, useSubmitCount, useSubmitForm, useValidateField, useValidateForm, validate, validateObjectSchema as validateObject };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vee-validate",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-beta.1",
|
|
4
4
|
"description": "Painless forms for Vue.js",
|
|
5
5
|
"author": "Abdelrahman Awad <logaretm1@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,6 +42,8 @@
|
|
|
42
42
|
"vue": "^3.4.26"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
+
"@standard-schema/spec": "^1.0.0",
|
|
46
|
+
"@standard-schema/utils": "^0.3.0",
|
|
45
47
|
"@vue/devtools-api": "^7.5.2",
|
|
46
48
|
"type-fest": "^4.8.3"
|
|
47
49
|
}
|