vee-validate 4.15.1 → 5.0.0-beta.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.
- package/README.md +4 -4
- package/dist/vee-validate.cjs +86 -102
- package/dist/vee-validate.d.ts +13 -36
- package/dist/vee-validate.iife.js +86 -102
- package/dist/vee-validate.iife.prod.js.mjs +2 -2
- package/dist/vee-validate.mjs +87 -103
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Painless Vue forms
|
|
|
18
18
|
<img src="https://img.shields.io/npm/dm/vee-validate.svg?color=05bd6d&label=">
|
|
19
19
|
</a>
|
|
20
20
|
|
|
21
|
-
<a href="https://vee-validate.logaretm.com/
|
|
21
|
+
<a href="https://vee-validate.logaretm.com/v5/" target="_blank">
|
|
22
22
|
<img src="https://img.shields.io/badge/-docs%20and%20demos-009f53">
|
|
23
23
|
</a>
|
|
24
24
|
|
|
@@ -69,7 +69,7 @@ The main v4 version supports Vue 3.x only, for previous versions of Vue, check t
|
|
|
69
69
|
| vue Version | vee-validate version | Documentation Link |
|
|
70
70
|
| ----------- | -------------------- | ---------------------------------------------------------------------------------------- |
|
|
71
71
|
| `2.x` | `2.x` or `3.x` | [v2](https://vee-validate.logaretm.com/v2) or [v3](https://vee-validate.logaretm.com/v3) |
|
|
72
|
-
| `3.x` | `4.x`
|
|
72
|
+
| `3.x` | `4.x` or `5.x` | [v4](https://vee-validate.logaretm.com/v4) or [v5](https://vee-validate.logaretm.com/v5) |
|
|
73
73
|
|
|
74
74
|
### Usage
|
|
75
75
|
|
|
@@ -117,7 +117,7 @@ const onSubmit = handleSubmit(values => {
|
|
|
117
117
|
</template>
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
-
You can do so much more than this, for more info [check the composition API documentation](https://vee-validate.logaretm.com/
|
|
120
|
+
You can do so much more than this, for more info [check the composition API documentation](https://vee-validate.logaretm.com/v5/guide/composition-api/getting-started/).
|
|
121
121
|
|
|
122
122
|
#### Declarative Components
|
|
123
123
|
|
|
@@ -150,7 +150,7 @@ function onSubmit(values) {
|
|
|
150
150
|
</template>
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
The `Field` component renders an `input` of type `text` by default but you can [control that](https://vee-validate.logaretm.com/
|
|
153
|
+
The `Field` component renders an `input` of type `text` by default but you can [control that](https://vee-validate.logaretm.com/v5/api/field#rendering-fields)
|
|
154
154
|
|
|
155
155
|
## 📚 Documentation
|
|
156
156
|
|
package/dist/vee-validate.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* vee-validate
|
|
2
|
+
* vee-validate v5.0.0-beta.0
|
|
3
3
|
* (c) 2025 Abdelrahman Awad
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -164,11 +164,8 @@ const isClient = typeof window !== 'undefined';
|
|
|
164
164
|
function isLocator(value) {
|
|
165
165
|
return isCallable(value) && !!value.__locatorRef;
|
|
166
166
|
}
|
|
167
|
-
function
|
|
168
|
-
return
|
|
169
|
-
}
|
|
170
|
-
function isYupValidator(value) {
|
|
171
|
-
return !!value && isCallable(value.validate);
|
|
167
|
+
function isStandardSchema(value) {
|
|
168
|
+
return isObject(value) && '~standard' in value;
|
|
172
169
|
}
|
|
173
170
|
function hasCheckedAttr(type) {
|
|
174
171
|
return type === 'checkbox' || type === 'radio';
|
|
@@ -348,6 +345,27 @@ function isFile(a) {
|
|
|
348
345
|
return a instanceof File;
|
|
349
346
|
}
|
|
350
347
|
|
|
348
|
+
// src/getDotPath/getDotPath.ts
|
|
349
|
+
function getDotPath(issue) {
|
|
350
|
+
if (issue.path?.length) {
|
|
351
|
+
let dotPath = "";
|
|
352
|
+
for (const item of issue.path) {
|
|
353
|
+
const key = typeof item === "object" ? item.key : item;
|
|
354
|
+
if (typeof key === "string" || typeof key === "number") {
|
|
355
|
+
if (dotPath) {
|
|
356
|
+
dotPath += `.${key}`;
|
|
357
|
+
} else {
|
|
358
|
+
dotPath += key;
|
|
359
|
+
}
|
|
360
|
+
} else {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return dotPath;
|
|
365
|
+
}
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
|
|
351
369
|
function cleanupNonNestedPath(path) {
|
|
352
370
|
if (isNotNestedPath(path)) {
|
|
353
371
|
return path.replace(/\[|\]/gi, '');
|
|
@@ -563,6 +581,31 @@ function debounceNextTick(inner) {
|
|
|
563
581
|
return new Promise(resolve => resolves.push(resolve));
|
|
564
582
|
};
|
|
565
583
|
}
|
|
584
|
+
function _combineIssueItems(items, getPath) {
|
|
585
|
+
const issueMap = {};
|
|
586
|
+
for (const item of items) {
|
|
587
|
+
const path = getPath(item);
|
|
588
|
+
if (!issueMap[path]) {
|
|
589
|
+
issueMap[path] = {
|
|
590
|
+
path,
|
|
591
|
+
messages: [],
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
if ('messages' in item) {
|
|
595
|
+
issueMap[path].messages.push(...item.messages);
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
issueMap[path].messages.push(item.message);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return Object.values(issueMap);
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Aggregates standard schema issues by path.
|
|
605
|
+
*/
|
|
606
|
+
function combineStandardIssues(issues) {
|
|
607
|
+
return _combineIssueItems(issues, issue => { var _a; return (issue.path ? (_a = getDotPath(issue)) !== null && _a !== void 0 ? _a : '' : ''); });
|
|
608
|
+
}
|
|
566
609
|
|
|
567
610
|
function normalizeChildren(tag, context, slotProps) {
|
|
568
611
|
if (!context.slots.default) {
|
|
@@ -769,8 +812,8 @@ async function validate(value, rules, options = {}) {
|
|
|
769
812
|
*/
|
|
770
813
|
async function _validate(field, value) {
|
|
771
814
|
const rules = field.rules;
|
|
772
|
-
if (
|
|
773
|
-
return
|
|
815
|
+
if (isStandardSchema(rules)) {
|
|
816
|
+
return validateFieldWithStandardSchema(value, Object.assign(Object.assign({}, field), { rules }));
|
|
774
817
|
}
|
|
775
818
|
// if a generic function or chain of generic functions
|
|
776
819
|
if (isCallable(rules) || Array.isArray(rules)) {
|
|
@@ -832,58 +875,24 @@ async function _validate(field, value) {
|
|
|
832
875
|
errors,
|
|
833
876
|
};
|
|
834
877
|
}
|
|
835
|
-
function isYupError(err) {
|
|
836
|
-
return !!err && err.name === 'ValidationError';
|
|
837
|
-
}
|
|
838
|
-
function yupToTypedSchema(yupSchema) {
|
|
839
|
-
const schema = {
|
|
840
|
-
__type: 'VVTypedSchema',
|
|
841
|
-
async parse(values, context) {
|
|
842
|
-
var _a;
|
|
843
|
-
try {
|
|
844
|
-
const output = await yupSchema.validate(values, { abortEarly: false, context: (context === null || context === void 0 ? void 0 : context.formData) || {} });
|
|
845
|
-
return {
|
|
846
|
-
output,
|
|
847
|
-
errors: [],
|
|
848
|
-
};
|
|
849
|
-
}
|
|
850
|
-
catch (err) {
|
|
851
|
-
// Yup errors have a name prop one them.
|
|
852
|
-
// https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string
|
|
853
|
-
if (!isYupError(err)) {
|
|
854
|
-
throw err;
|
|
855
|
-
}
|
|
856
|
-
if (!((_a = err.inner) === null || _a === void 0 ? void 0 : _a.length) && err.errors.length) {
|
|
857
|
-
return { errors: [{ path: err.path, errors: err.errors }] };
|
|
858
|
-
}
|
|
859
|
-
const errors = err.inner.reduce((acc, curr) => {
|
|
860
|
-
const path = curr.path || '';
|
|
861
|
-
if (!acc[path]) {
|
|
862
|
-
acc[path] = { errors: [], path };
|
|
863
|
-
}
|
|
864
|
-
acc[path].errors.push(...curr.errors);
|
|
865
|
-
return acc;
|
|
866
|
-
}, {});
|
|
867
|
-
return { errors: Object.values(errors) };
|
|
868
|
-
}
|
|
869
|
-
},
|
|
870
|
-
};
|
|
871
|
-
return schema;
|
|
872
|
-
}
|
|
873
878
|
/**
|
|
874
879
|
* Handles yup validation
|
|
875
880
|
*/
|
|
876
|
-
async function
|
|
877
|
-
const
|
|
878
|
-
|
|
881
|
+
async function validateFieldWithStandardSchema(value, context) {
|
|
882
|
+
const result = await context.rules['~standard'].validate(value);
|
|
883
|
+
if (!result.issues) {
|
|
884
|
+
return {
|
|
885
|
+
value: result.value,
|
|
886
|
+
errors: [],
|
|
887
|
+
};
|
|
888
|
+
}
|
|
879
889
|
const messages = [];
|
|
880
|
-
for (const error of result.
|
|
881
|
-
if (error.
|
|
882
|
-
messages.push(
|
|
890
|
+
for (const error of result.issues) {
|
|
891
|
+
if (error.message) {
|
|
892
|
+
messages.push(error.message);
|
|
883
893
|
}
|
|
884
894
|
}
|
|
885
895
|
return {
|
|
886
|
-
value: result.value,
|
|
887
896
|
errors: messages,
|
|
888
897
|
};
|
|
889
898
|
}
|
|
@@ -939,27 +948,33 @@ function fillTargetValues(params, crossTable) {
|
|
|
939
948
|
return acc;
|
|
940
949
|
}, {});
|
|
941
950
|
}
|
|
942
|
-
async function
|
|
943
|
-
const
|
|
944
|
-
const validationResult = await typedSchema.parse(klona(values), { formData: klona(values) });
|
|
951
|
+
async function validateStandardSchema(schema, values) {
|
|
952
|
+
const validationResult = await schema['~standard'].validate(klona(values));
|
|
945
953
|
const results = {};
|
|
946
954
|
const errors = {};
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
955
|
+
if (!validationResult.issues) {
|
|
956
|
+
return {
|
|
957
|
+
valid: true,
|
|
958
|
+
results: {},
|
|
959
|
+
errors: {},
|
|
960
|
+
values: validationResult.value,
|
|
961
|
+
source: 'schema',
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
const combinedIssues = combineStandardIssues(validationResult.issues || []);
|
|
965
|
+
for (const error of combinedIssues) {
|
|
966
|
+
const messages = error.messages;
|
|
967
|
+
const path = error.path;
|
|
953
968
|
results[path] = { valid: !messages.length, errors: messages };
|
|
954
969
|
if (messages.length) {
|
|
955
970
|
errors[path] = messages[0];
|
|
956
971
|
}
|
|
957
972
|
}
|
|
958
973
|
return {
|
|
959
|
-
valid: !
|
|
974
|
+
valid: !combinedIssues.length,
|
|
960
975
|
results,
|
|
961
976
|
errors,
|
|
962
|
-
values:
|
|
977
|
+
values: undefined,
|
|
963
978
|
source: 'schema',
|
|
964
979
|
};
|
|
965
980
|
}
|
|
@@ -1004,7 +1019,7 @@ function useFieldState(path, init) {
|
|
|
1004
1019
|
if (!init.form) {
|
|
1005
1020
|
const { errors, setErrors } = createFieldErrors();
|
|
1006
1021
|
const id = ID_COUNTER >= Number.MAX_SAFE_INTEGER ? 0 : ++ID_COUNTER;
|
|
1007
|
-
const meta = createFieldMeta(value, initialValue, errors
|
|
1022
|
+
const meta = createFieldMeta(value, initialValue, errors);
|
|
1008
1023
|
function setState(state) {
|
|
1009
1024
|
var _a;
|
|
1010
1025
|
if ('value' in state) {
|
|
@@ -1036,7 +1051,6 @@ function useFieldState(path, init) {
|
|
|
1036
1051
|
label: init.label,
|
|
1037
1052
|
type: init.type,
|
|
1038
1053
|
validate: init.validate,
|
|
1039
|
-
schema: init.schema,
|
|
1040
1054
|
});
|
|
1041
1055
|
const errors = vue.computed(() => state.errors);
|
|
1042
1056
|
function setState(state) {
|
|
@@ -1132,13 +1146,11 @@ function resolveModelValue(modelValue, form, initialValue, path) {
|
|
|
1132
1146
|
/**
|
|
1133
1147
|
* Creates meta flags state and some associated effects with them
|
|
1134
1148
|
*/
|
|
1135
|
-
function createFieldMeta(currentValue, initialValue, errors
|
|
1136
|
-
const isRequired = vue.computed(() => { var _a, _b, _c; return (_c = (_b = (_a = vue.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; });
|
|
1149
|
+
function createFieldMeta(currentValue, initialValue, errors) {
|
|
1137
1150
|
const meta = vue.reactive({
|
|
1138
1151
|
touched: false,
|
|
1139
1152
|
pending: false,
|
|
1140
1153
|
valid: true,
|
|
1141
|
-
required: isRequired,
|
|
1142
1154
|
validated: !!vue.unref(errors).length,
|
|
1143
1155
|
initialValue: vue.computed(() => vue.unref(initialValue)),
|
|
1144
1156
|
dirty: vue.computed(() => {
|
|
@@ -1186,15 +1198,11 @@ function _useField(path, rules, opts) {
|
|
|
1186
1198
|
return undefined;
|
|
1187
1199
|
}
|
|
1188
1200
|
const rulesValue = vue.unref(rules);
|
|
1189
|
-
if (
|
|
1190
|
-
isTypedSchema(rulesValue) ||
|
|
1191
|
-
isCallable(rulesValue) ||
|
|
1192
|
-
Array.isArray(rulesValue)) {
|
|
1201
|
+
if (isStandardSchema(rulesValue) || isCallable(rulesValue) || Array.isArray(rulesValue)) {
|
|
1193
1202
|
return rulesValue;
|
|
1194
1203
|
}
|
|
1195
1204
|
return normalizeRules(rulesValue);
|
|
1196
1205
|
});
|
|
1197
|
-
const isTyped = !isCallable(validator.value) && isTypedSchema(vue.toValue(rules));
|
|
1198
1206
|
const { id, value, initialValue, meta, setState, errors, flags } = useFieldState(name, {
|
|
1199
1207
|
modelValue,
|
|
1200
1208
|
form,
|
|
@@ -1202,7 +1210,6 @@ function _useField(path, rules, opts) {
|
|
|
1202
1210
|
label,
|
|
1203
1211
|
type,
|
|
1204
1212
|
validate: validator.value ? validate$1 : undefined,
|
|
1205
|
-
schema: isTyped ? rules : undefined,
|
|
1206
1213
|
});
|
|
1207
1214
|
const errorMessage = vue.computed(() => errors.value[0]);
|
|
1208
1215
|
if (syncVModel) {
|
|
@@ -1354,12 +1361,8 @@ function _useField(path, rules, opts) {
|
|
|
1354
1361
|
// extract cross-field dependencies in a computed prop
|
|
1355
1362
|
const dependencies = vue.computed(() => {
|
|
1356
1363
|
const rulesVal = validator.value;
|
|
1357
|
-
// is falsy, a function schema or a
|
|
1358
|
-
if (!rulesVal ||
|
|
1359
|
-
isCallable(rulesVal) ||
|
|
1360
|
-
isYupValidator(rulesVal) ||
|
|
1361
|
-
isTypedSchema(rulesVal) ||
|
|
1362
|
-
Array.isArray(rulesVal)) {
|
|
1364
|
+
// is falsy, a function schema or a standard schema
|
|
1365
|
+
if (!rulesVal || isCallable(rulesVal) || isStandardSchema(rulesVal) || Array.isArray(rulesVal)) {
|
|
1363
1366
|
return {};
|
|
1364
1367
|
}
|
|
1365
1368
|
return Object.keys(rulesVal).reduce((acc, rule) => {
|
|
@@ -1734,10 +1737,6 @@ const PRIVATE_PATH_STATE_KEYS = ['bails', 'fieldsCount', 'id', 'multiple', 'type
|
|
|
1734
1737
|
function resolveInitialValues(opts) {
|
|
1735
1738
|
const givenInitial = (opts === null || opts === void 0 ? void 0 : opts.initialValues) || {};
|
|
1736
1739
|
const providedValues = Object.assign({}, vue.toValue(givenInitial));
|
|
1737
|
-
const schema = vue.unref(opts === null || opts === void 0 ? void 0 : opts.validationSchema);
|
|
1738
|
-
if (schema && isTypedSchema(schema) && isCallable(schema.cast)) {
|
|
1739
|
-
return klona(schema.cast(providedValues) || {});
|
|
1740
|
-
}
|
|
1741
1740
|
return klona(providedValues);
|
|
1742
1741
|
}
|
|
1743
1742
|
function useForm(opts) {
|
|
@@ -1872,19 +1871,6 @@ function useForm(opts) {
|
|
|
1872
1871
|
if (unsetBatchIndex !== -1) {
|
|
1873
1872
|
UNSET_BATCH.splice(unsetBatchIndex, 1);
|
|
1874
1873
|
}
|
|
1875
|
-
const isRequired = vue.computed(() => {
|
|
1876
|
-
var _a, _b, _c, _d;
|
|
1877
|
-
const schemaValue = vue.toValue(schema);
|
|
1878
|
-
if (isTypedSchema(schemaValue)) {
|
|
1879
|
-
return (_b = (_a = schemaValue.describe) === null || _a === void 0 ? void 0 : _a.call(schemaValue, vue.toValue(path)).required) !== null && _b !== void 0 ? _b : false;
|
|
1880
|
-
}
|
|
1881
|
-
// Path own schema
|
|
1882
|
-
const configSchemaValue = vue.toValue(config === null || config === void 0 ? void 0 : config.schema);
|
|
1883
|
-
if (isTypedSchema(configSchemaValue)) {
|
|
1884
|
-
return (_d = (_c = configSchemaValue.describe) === null || _c === void 0 ? void 0 : _c.call(configSchemaValue).required) !== null && _d !== void 0 ? _d : false;
|
|
1885
|
-
}
|
|
1886
|
-
return false;
|
|
1887
|
-
});
|
|
1888
1874
|
const id = FIELD_ID_COUNTER++;
|
|
1889
1875
|
const state = vue.reactive({
|
|
1890
1876
|
id,
|
|
@@ -1893,7 +1879,6 @@ function useForm(opts) {
|
|
|
1893
1879
|
pending: false,
|
|
1894
1880
|
valid: true,
|
|
1895
1881
|
validated: !!((_a = initialErrors[pathValue]) === null || _a === void 0 ? void 0 : _a.length),
|
|
1896
|
-
required: isRequired,
|
|
1897
1882
|
initialValue,
|
|
1898
1883
|
errors: vue.shallowRef([]),
|
|
1899
1884
|
bails: (_b = config === null || config === void 0 ? void 0 : config.bails) !== null && _b !== void 0 ? _b : false,
|
|
@@ -2306,7 +2291,6 @@ function useForm(opts) {
|
|
|
2306
2291
|
function resetForm(resetState, opts) {
|
|
2307
2292
|
let newValues = klona((resetState === null || resetState === void 0 ? void 0 : resetState.values) ? resetState.values : originalInitialValues.value);
|
|
2308
2293
|
newValues = (opts === null || opts === void 0 ? void 0 : opts.force) ? newValues : merge(originalInitialValues.value, newValues);
|
|
2309
|
-
newValues = isTypedSchema(schema) && isCallable(schema.cast) ? schema.cast(newValues) : newValues;
|
|
2310
2294
|
setInitialValues(newValues, { force: opts === null || opts === void 0 ? void 0 : opts.force });
|
|
2311
2295
|
mutateAllPathState(state => {
|
|
2312
2296
|
var _a;
|
|
@@ -2419,8 +2403,8 @@ function useForm(opts) {
|
|
|
2419
2403
|
return { valid: true, results: {}, errors: {}, source: 'none' };
|
|
2420
2404
|
}
|
|
2421
2405
|
isValidating.value = true;
|
|
2422
|
-
const formResult =
|
|
2423
|
-
? await
|
|
2406
|
+
const formResult = isStandardSchema(schemaValue)
|
|
2407
|
+
? await validateStandardSchema(schemaValue, formValues)
|
|
2424
2408
|
: await validateObjectSchema(schemaValue, formValues, {
|
|
2425
2409
|
names: fieldNames.value,
|
|
2426
2410
|
bailsMap: fieldBailsMap.value,
|
package/dist/vee-validate.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { MaybeRef, Ref, MaybeRefOrGetter, ComputedRef, PropType, VNode, UnwrapRef, InjectionKey } from 'vue';
|
|
3
3
|
import { PartialDeep } from 'type-fest';
|
|
4
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
5
|
|
|
5
6
|
type BrowserNativeObject = Date | FileList | File;
|
|
6
7
|
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
@@ -177,32 +178,6 @@ interface ValidationResult<TValue = unknown> {
|
|
|
177
178
|
type FlattenAndMapPathsValidationResult<TInput extends GenericObject, TOutput extends GenericObject> = {
|
|
178
179
|
[K in Path<TInput>]: ValidationResult<TOutput[K]>;
|
|
179
180
|
};
|
|
180
|
-
interface TypedSchemaError {
|
|
181
|
-
path?: string;
|
|
182
|
-
errors: string[];
|
|
183
|
-
}
|
|
184
|
-
interface TypedSchemaPathDescription {
|
|
185
|
-
required: boolean;
|
|
186
|
-
exists: boolean;
|
|
187
|
-
}
|
|
188
|
-
interface TypedSchemaContext {
|
|
189
|
-
formData: GenericObject;
|
|
190
|
-
}
|
|
191
|
-
interface TypedSchema<TInput = any, TOutput = TInput> {
|
|
192
|
-
__type: 'VVTypedSchema';
|
|
193
|
-
parse(values: TInput, context?: TypedSchemaContext): Promise<{
|
|
194
|
-
value?: TOutput;
|
|
195
|
-
errors: TypedSchemaError[];
|
|
196
|
-
}>;
|
|
197
|
-
cast?(values: Partial<TInput>): TInput;
|
|
198
|
-
describe?(path?: Path<TInput>): Partial<TypedSchemaPathDescription>;
|
|
199
|
-
}
|
|
200
|
-
type InferOutput<TSchema extends TypedSchema> = TSchema extends TypedSchema<any, infer TOutput> ? TOutput : never;
|
|
201
|
-
type InferInput<TSchema extends TypedSchema> = TSchema extends TypedSchema<infer TInput, any> ? TInput : never;
|
|
202
|
-
type YupSchema<TValues = any> = {
|
|
203
|
-
__isYupSchema__: boolean;
|
|
204
|
-
validate(value: any, options: GenericObject): Promise<any>;
|
|
205
|
-
};
|
|
206
181
|
type Locator = {
|
|
207
182
|
__locatorRef: string;
|
|
208
183
|
} & ((values: GenericObject) => unknown);
|
|
@@ -211,7 +186,6 @@ interface FieldMeta<TValue> {
|
|
|
211
186
|
dirty: boolean;
|
|
212
187
|
valid: boolean;
|
|
213
188
|
validated: boolean;
|
|
214
|
-
required: boolean;
|
|
215
189
|
pending: boolean;
|
|
216
190
|
initialValue?: TValue;
|
|
217
191
|
}
|
|
@@ -244,15 +218,18 @@ interface PathStateConfig<TOutput> {
|
|
|
244
218
|
label: MaybeRefOrGetter<string | undefined>;
|
|
245
219
|
type: InputType;
|
|
246
220
|
validate: FieldValidator<TOutput>;
|
|
247
|
-
schema?: MaybeRefOrGetter<
|
|
221
|
+
schema?: MaybeRefOrGetter<StandardSchemaV1 | undefined>;
|
|
248
222
|
}
|
|
223
|
+
type IssueCollection<TPath = string> = {
|
|
224
|
+
path: TPath;
|
|
225
|
+
messages: string[];
|
|
226
|
+
};
|
|
249
227
|
interface PathState<TInput = unknown, TOutput = TInput> {
|
|
250
228
|
id: number | number[];
|
|
251
229
|
path: string;
|
|
252
230
|
touched: boolean;
|
|
253
231
|
dirty: boolean;
|
|
254
232
|
valid: boolean;
|
|
255
|
-
required: boolean;
|
|
256
233
|
validated: boolean;
|
|
257
234
|
pending: boolean;
|
|
258
235
|
initialValue: TInput | undefined;
|
|
@@ -415,7 +392,7 @@ interface PrivateFormContext<TValues extends GenericObject = GenericObject, TOut
|
|
|
415
392
|
controlledValues: Ref<TValues>;
|
|
416
393
|
fieldArrays: PrivateFieldArrayContext[];
|
|
417
394
|
submitCount: Ref<number>;
|
|
418
|
-
schema?: MaybeRef<RawFormSchema<TValues> |
|
|
395
|
+
schema?: MaybeRef<RawFormSchema<TValues> | StandardSchemaV1<TValues, TOutput> | undefined>;
|
|
419
396
|
errorBag: Ref<FormErrorBag<TValues>>;
|
|
420
397
|
errors: ComputedRef<FormErrors<TValues>>;
|
|
421
398
|
meta: ComputedRef<FormMeta<TValues>>;
|
|
@@ -489,7 +466,7 @@ interface ValidationOptions {
|
|
|
489
466
|
/**
|
|
490
467
|
* Validates a value against the rules.
|
|
491
468
|
*/
|
|
492
|
-
declare function validate<TInput, TOutput>(value: TInput, rules: string | Record<string, unknown | unknown[]> | GenericValidateFunction<TInput> | GenericValidateFunction<TInput>[] |
|
|
469
|
+
declare function validate<TInput, TOutput>(value: TInput, rules: string | Record<string, unknown | unknown[]> | GenericValidateFunction<TInput> | GenericValidateFunction<TInput>[] | StandardSchemaV1<TInput, TOutput>, options?: ValidationOptions): Promise<ValidationResult<TOutput>>;
|
|
493
470
|
declare function validateObjectSchema<TValues extends GenericObject, TOutput extends GenericObject>(schema: RawFormSchema<TValues>, values: TValues | undefined, opts?: Partial<{
|
|
494
471
|
names: Record<string, {
|
|
495
472
|
name: string;
|
|
@@ -551,7 +528,7 @@ interface FieldOptions<TValue = unknown> {
|
|
|
551
528
|
syncVModel?: boolean | string;
|
|
552
529
|
form?: FormContext;
|
|
553
530
|
}
|
|
554
|
-
type RuleExpression<TValue> = string | Record<string, unknown> | GenericValidateFunction<TValue> | GenericValidateFunction<TValue>[] |
|
|
531
|
+
type RuleExpression<TValue> = string | Record<string, unknown> | GenericValidateFunction<TValue> | GenericValidateFunction<TValue>[] | StandardSchemaV1<TValue> | undefined;
|
|
555
532
|
/**
|
|
556
533
|
* Creates a field composite.
|
|
557
534
|
*/
|
|
@@ -1354,8 +1331,8 @@ declare const ErrorMessage: {
|
|
|
1354
1331
|
});
|
|
1355
1332
|
|
|
1356
1333
|
type FormSchema<TValues extends Record<string, unknown>> = FlattenAndSetPathsType<TValues, GenericValidateFunction | string | GenericObject> | undefined;
|
|
1357
|
-
interface FormOptions<TValues extends GenericObject, TOutput = TValues, TSchema extends
|
|
1358
|
-
validationSchema?: MaybeRef<TSchema extends
|
|
1334
|
+
interface FormOptions<TValues extends GenericObject, TOutput = TValues, TSchema extends StandardSchemaV1<TValues, TOutput> | FormSchema<TValues> = FormSchema<TValues>> {
|
|
1335
|
+
validationSchema?: MaybeRef<TSchema extends StandardSchemaV1 ? StandardSchemaV1<TValues, TOutput> : any>;
|
|
1359
1336
|
initialValues?: PartialDeep<TValues> | undefined | null;
|
|
1360
1337
|
initialErrors?: FlattenAndSetPathsType<TValues, string | undefined>;
|
|
1361
1338
|
initialTouched?: FlattenAndSetPathsType<TValues, boolean>;
|
|
@@ -1363,7 +1340,7 @@ interface FormOptions<TValues extends GenericObject, TOutput = TValues, TSchema
|
|
|
1363
1340
|
keepValuesOnUnmount?: MaybeRef<boolean>;
|
|
1364
1341
|
name?: string;
|
|
1365
1342
|
}
|
|
1366
|
-
declare function useForm<TValues extends GenericObject = GenericObject, TOutput extends GenericObject = TValues, TSchema extends FormSchema<TValues> |
|
|
1343
|
+
declare function useForm<TValues extends GenericObject = GenericObject, TOutput extends GenericObject = TValues, TSchema extends FormSchema<TValues> | StandardSchemaV1<TValues, TOutput> = FormSchema<TValues>>(opts?: FormOptions<TValues, TOutput, TSchema>): FormContext<TValues, TOutput>;
|
|
1367
1344
|
declare function useFormContext<TValues extends GenericObject = GenericObject, TOutput extends GenericObject = TValues>(): FormContext<TValues, TOutput>;
|
|
1368
1345
|
|
|
1369
1346
|
declare function useFieldArray<TValue = unknown>(arrayPath: MaybeRefOrGetter<string>): FieldArrayContext<TValue>;
|
|
@@ -1482,4 +1459,4 @@ declare const PublicFormContextKey: InjectionKey<FormContext>;
|
|
|
1482
1459
|
declare const FieldContextKey: InjectionKey<PrivateFieldContext<unknown>>;
|
|
1483
1460
|
declare const IS_ABSENT: unique symbol;
|
|
1484
1461
|
|
|
1485
|
-
export { type BaseComponentBinds, type BaseFieldProps, type BaseInputBinds, type ComponentBindsConfig, type ComponentFieldBindingObject, type ComponentModelBinds, type ComponentModellessBinds, type DevtoolsPluginFieldState, type DevtoolsPluginFormState, ErrorMessage, Field, FieldArray, type FieldArrayContext, type FieldBindingObject, type FieldContext, FieldContextKey, type FieldEntry, type FieldMeta, type FieldOptions, type FieldPathLookup, type FieldSlotProps, type FieldState, type FieldValidator, type FlattenAndMapPathsValidationResult, type FlattenAndSetPathsType, Form, type FormActions, type FormContext, FormContextKey, type FormErrorBag, type FormErrors, type FormMeta, type FormOptions, type FormSlotProps, type FormState, type FormValidationResult, type GenericObject, type GenericValidateFunction, IS_ABSENT, type
|
|
1462
|
+
export { type BaseComponentBinds, type BaseFieldProps, type BaseInputBinds, type ComponentBindsConfig, type ComponentFieldBindingObject, type ComponentModelBinds, type ComponentModellessBinds, type DevtoolsPluginFieldState, type DevtoolsPluginFormState, ErrorMessage, Field, FieldArray, type FieldArrayContext, type FieldBindingObject, type FieldContext, FieldContextKey, type FieldEntry, type FieldMeta, type FieldOptions, type FieldPathLookup, type FieldSlotProps, type FieldState, type FieldValidator, type FlattenAndMapPathsValidationResult, type FlattenAndSetPathsType, Form, type FormActions, type FormContext, FormContextKey, type FormErrorBag, type FormErrors, type FormMeta, type FormOptions, type FormSlotProps, type FormState, type FormValidationResult, type GenericObject, type GenericValidateFunction, IS_ABSENT, type InputBindsConfig, type InputType, type InvalidSubmissionContext, type InvalidSubmissionHandler, type IsAny, type IsEqual, type IssueCollection, type LazyComponentBindsConfig, type LazyInputBindsConfig, type Locator, type MapValuesPathsToRefs, type MaybeArray, type MaybePromise, type Path, type PathState, type PathStateConfig, type PathValue, type PrivateFieldArrayContext, type PrivateFieldContext, type PrivateFormContext, PublicFormContextKey, type PublicPathState, type RawFormSchema, type ResetFormOpts, type RuleExpression, type SchemaValidationMode, type SubmissionContext, type SubmissionHandler, type ValidationOptions$1 as ValidationOptions, type ValidationResult, 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 };
|