vee-validate 4.12.0-alpha.1 → 4.12.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/dist/vee-validate.d.ts +277 -243
- package/dist/vee-validate.esm.js +142 -64
- package/dist/vee-validate.js +143 -63
- package/dist/vee-validate.min.js +2 -2
- package/package.json +4 -4
package/dist/vee-validate.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* vee-validate v4.12.
|
|
2
|
+
* vee-validate v4.12.1
|
|
3
3
|
* (c) 2023 Abdelrahman Awad
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -505,8 +505,7 @@ function withLatest(fn, onDone) {
|
|
|
505
505
|
return result;
|
|
506
506
|
}
|
|
507
507
|
latestRun = undefined;
|
|
508
|
-
onDone(result, args);
|
|
509
|
-
return result;
|
|
508
|
+
return onDone(result, args);
|
|
510
509
|
};
|
|
511
510
|
}
|
|
512
511
|
function computedDeep({ get, set }) {
|
|
@@ -1012,7 +1011,7 @@ function useFieldState(path, init) {
|
|
|
1012
1011
|
if (!init.form) {
|
|
1013
1012
|
const { errors, setErrors } = createFieldErrors();
|
|
1014
1013
|
const id = ID_COUNTER >= Number.MAX_SAFE_INTEGER ? 0 : ++ID_COUNTER;
|
|
1015
|
-
const meta = createFieldMeta(value, initialValue, errors);
|
|
1014
|
+
const meta = createFieldMeta(value, initialValue, errors, init.schema);
|
|
1016
1015
|
function setState(state) {
|
|
1017
1016
|
var _a;
|
|
1018
1017
|
if ('value' in state) {
|
|
@@ -1044,6 +1043,7 @@ function useFieldState(path, init) {
|
|
|
1044
1043
|
label: init.label,
|
|
1045
1044
|
type: init.type,
|
|
1046
1045
|
validate: init.validate,
|
|
1046
|
+
schema: init.schema,
|
|
1047
1047
|
});
|
|
1048
1048
|
const errors = computed(() => state.errors);
|
|
1049
1049
|
function setState(state) {
|
|
@@ -1088,7 +1088,7 @@ function _useFieldValue(path, modelValue, form) {
|
|
|
1088
1088
|
modelRef.value = value;
|
|
1089
1089
|
return;
|
|
1090
1090
|
}
|
|
1091
|
-
form.
|
|
1091
|
+
form.setFieldInitialValue(unref(path), value, true);
|
|
1092
1092
|
}
|
|
1093
1093
|
const initialValue = computed(resolveInitialValue);
|
|
1094
1094
|
// if no form is associated, use a regular ref.
|
|
@@ -1139,11 +1139,14 @@ function resolveModelValue(modelValue, form, initialValue, path) {
|
|
|
1139
1139
|
/**
|
|
1140
1140
|
* Creates meta flags state and some associated effects with them
|
|
1141
1141
|
*/
|
|
1142
|
-
function createFieldMeta(currentValue, initialValue, errors) {
|
|
1142
|
+
function createFieldMeta(currentValue, initialValue, errors, schema) {
|
|
1143
|
+
var _a, _b;
|
|
1144
|
+
const isRequired = (_b = (_a = schema === null || schema === void 0 ? void 0 : schema.describe) === null || _a === void 0 ? void 0 : _a.call(schema).required) !== null && _b !== void 0 ? _b : false;
|
|
1143
1145
|
const meta = reactive({
|
|
1144
1146
|
touched: false,
|
|
1145
1147
|
pending: false,
|
|
1146
1148
|
valid: true,
|
|
1149
|
+
required: isRequired,
|
|
1147
1150
|
validated: !!unref(errors).length,
|
|
1148
1151
|
initialValue: computed(() => unref(initialValue)),
|
|
1149
1152
|
dirty: computed(() => {
|
|
@@ -1589,6 +1592,7 @@ function _useField(path, rules, opts) {
|
|
|
1589
1592
|
label,
|
|
1590
1593
|
type,
|
|
1591
1594
|
validate: validator.value ? validate$1 : undefined,
|
|
1595
|
+
schema: isTypedSchema(rules) ? rules : undefined,
|
|
1592
1596
|
});
|
|
1593
1597
|
const errorMessage = computed(() => errors.value[0]);
|
|
1594
1598
|
if (syncVModel) {
|
|
@@ -1611,7 +1615,8 @@ function _useField(path, rules, opts) {
|
|
|
1611
1615
|
async function validateCurrentValue(mode) {
|
|
1612
1616
|
var _a, _b;
|
|
1613
1617
|
if (form === null || form === void 0 ? void 0 : form.validateSchema) {
|
|
1614
|
-
|
|
1618
|
+
const { results } = await form.validateSchema(mode);
|
|
1619
|
+
return (_a = results[toValue(name)]) !== null && _a !== void 0 ? _a : { valid: true, errors: [] };
|
|
1615
1620
|
}
|
|
1616
1621
|
if (validator.value) {
|
|
1617
1622
|
return validate(value.value, validator.value, {
|
|
@@ -1629,7 +1634,7 @@ function _useField(path, rules, opts) {
|
|
|
1629
1634
|
return validateCurrentValue('validated-only');
|
|
1630
1635
|
}, result => {
|
|
1631
1636
|
if (flags.pendingUnmount[field.id]) {
|
|
1632
|
-
return;
|
|
1637
|
+
return result;
|
|
1633
1638
|
}
|
|
1634
1639
|
setState({ errors: result.errors });
|
|
1635
1640
|
meta.pending = false;
|
|
@@ -2087,6 +2092,10 @@ const FieldImpl = /** #__PURE__ */ defineComponent({
|
|
|
2087
2092
|
};
|
|
2088
2093
|
}
|
|
2089
2094
|
ctx.expose({
|
|
2095
|
+
value,
|
|
2096
|
+
meta,
|
|
2097
|
+
errors,
|
|
2098
|
+
errorMessage,
|
|
2090
2099
|
setErrors,
|
|
2091
2100
|
setTouched,
|
|
2092
2101
|
reset: resetField,
|
|
@@ -2133,7 +2142,7 @@ const Field = FieldImpl;
|
|
|
2133
2142
|
let FORM_COUNTER = 0;
|
|
2134
2143
|
const PRIVATE_PATH_STATE_KEYS = ['bails', 'fieldsCount', 'id', 'multiple', 'type', 'validate'];
|
|
2135
2144
|
function resolveInitialValues(opts) {
|
|
2136
|
-
const providedValues =
|
|
2145
|
+
const providedValues = toValue((opts === null || opts === void 0 ? void 0 : opts.initialValues) || {});
|
|
2137
2146
|
const schema = unref(opts === null || opts === void 0 ? void 0 : opts.validationSchema);
|
|
2138
2147
|
if (schema && isTypedSchema(schema) && isCallable(schema.cast)) {
|
|
2139
2148
|
return klona(schema.cast(providedValues) || {});
|
|
@@ -2251,10 +2260,9 @@ function useForm(opts) {
|
|
|
2251
2260
|
var _a, _b;
|
|
2252
2261
|
const initialValue = computed(() => getFromPath(initialValues.value, toValue(path)));
|
|
2253
2262
|
const pathStateExists = pathStateLookup.value[toValue(path)];
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
}
|
|
2263
|
+
const isCheckboxOrRadio = (config === null || config === void 0 ? void 0 : config.type) === 'checkbox' || (config === null || config === void 0 ? void 0 : config.type) === 'radio';
|
|
2264
|
+
if (pathStateExists && isCheckboxOrRadio) {
|
|
2265
|
+
pathStateExists.multiple = true;
|
|
2258
2266
|
const id = FIELD_ID_COUNTER++;
|
|
2259
2267
|
if (Array.isArray(pathStateExists.id)) {
|
|
2260
2268
|
pathStateExists.id.push(id);
|
|
@@ -2268,6 +2276,17 @@ function useForm(opts) {
|
|
|
2268
2276
|
}
|
|
2269
2277
|
const currentValue = computed(() => getFromPath(formValues, toValue(path)));
|
|
2270
2278
|
const pathValue = toValue(path);
|
|
2279
|
+
const isRequired = computed(() => {
|
|
2280
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2281
|
+
if (isTypedSchema(schema)) {
|
|
2282
|
+
return (_c = (_b = (_a = schema).describe) === null || _b === void 0 ? void 0 : _b.call(_a, toValue(path)).required) !== null && _c !== void 0 ? _c : false;
|
|
2283
|
+
}
|
|
2284
|
+
// Path own schema
|
|
2285
|
+
if (isTypedSchema(config === null || config === void 0 ? void 0 : config.schema)) {
|
|
2286
|
+
return (_f = (_e = (_d = (config === null || config === void 0 ? void 0 : config.schema)).describe) === null || _e === void 0 ? void 0 : _e.call(_d).required) !== null && _f !== void 0 ? _f : false;
|
|
2287
|
+
}
|
|
2288
|
+
return false;
|
|
2289
|
+
});
|
|
2271
2290
|
const id = FIELD_ID_COUNTER++;
|
|
2272
2291
|
const state = reactive({
|
|
2273
2292
|
id,
|
|
@@ -2276,6 +2295,7 @@ function useForm(opts) {
|
|
|
2276
2295
|
pending: false,
|
|
2277
2296
|
valid: true,
|
|
2278
2297
|
validated: !!((_a = initialErrors[pathValue]) === null || _a === void 0 ? void 0 : _a.length),
|
|
2298
|
+
required: isRequired,
|
|
2279
2299
|
initialValue,
|
|
2280
2300
|
errors: shallowRef([]),
|
|
2281
2301
|
bails: (_b = config === null || config === void 0 ? void 0 : config.bails) !== null && _b !== void 0 ? _b : false,
|
|
@@ -2321,7 +2341,9 @@ function useForm(opts) {
|
|
|
2321
2341
|
const debouncedSilentValidation = debounceAsync(_validateSchema, 5);
|
|
2322
2342
|
const debouncedValidation = debounceAsync(_validateSchema, 5);
|
|
2323
2343
|
const validateSchema = withLatest(async (mode) => {
|
|
2324
|
-
return (await mode
|
|
2344
|
+
return (await (mode === 'silent'
|
|
2345
|
+
? debouncedSilentValidation()
|
|
2346
|
+
: debouncedValidation()));
|
|
2325
2347
|
}, (formResult, [mode]) => {
|
|
2326
2348
|
// fields by id lookup
|
|
2327
2349
|
// errors fields names, we need it to also check if custom errors are updated
|
|
@@ -2332,14 +2354,16 @@ function useForm(opts) {
|
|
|
2332
2354
|
...new Set([...keysOf(formResult.results), ...pathStates.value.map(p => p.path), ...currentErrorsPaths]),
|
|
2333
2355
|
].sort();
|
|
2334
2356
|
// aggregates the paths into a single result object while applying the results on the fields
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
const
|
|
2338
|
-
const
|
|
2339
|
-
const
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2357
|
+
const results = paths.reduce((validation, _path) => {
|
|
2358
|
+
var _a;
|
|
2359
|
+
const expectedPath = _path;
|
|
2360
|
+
const pathState = findPathState(expectedPath) || findHoistedPath(expectedPath);
|
|
2361
|
+
const messages = ((_a = formResult.results[expectedPath]) === null || _a === void 0 ? void 0 : _a.errors) || [];
|
|
2362
|
+
// This is the real path of the field, because it might've been a hoisted field
|
|
2363
|
+
const path = (toValue(pathState === null || pathState === void 0 ? void 0 : pathState.path) || expectedPath);
|
|
2364
|
+
// It is possible that multiple paths are collected across loops
|
|
2365
|
+
// We want to merge them to avoid overriding any iteration's results
|
|
2366
|
+
const fieldResult = mergeValidationResults({ errors: messages, valid: !messages.length }, validation.results[path]);
|
|
2343
2367
|
validation.results[path] = fieldResult;
|
|
2344
2368
|
if (!fieldResult.valid) {
|
|
2345
2369
|
validation.errors[path] = fieldResult.errors[0];
|
|
@@ -2364,6 +2388,7 @@ function useForm(opts) {
|
|
|
2364
2388
|
setFieldError(pathState, fieldResult.errors);
|
|
2365
2389
|
return validation;
|
|
2366
2390
|
}, { valid: formResult.valid, results: {}, errors: {} });
|
|
2391
|
+
return results;
|
|
2367
2392
|
});
|
|
2368
2393
|
function mutateAllPathState(mutation) {
|
|
2369
2394
|
pathStates.value.forEach(mutation);
|
|
@@ -2480,14 +2505,16 @@ function useForm(opts) {
|
|
|
2480
2505
|
delete pathStateLookup.value[path];
|
|
2481
2506
|
}
|
|
2482
2507
|
}
|
|
2483
|
-
function
|
|
2484
|
-
|
|
2485
|
-
if (
|
|
2486
|
-
|
|
2487
|
-
s.__flags.pendingUnmount[id] = true;
|
|
2488
|
-
});
|
|
2508
|
+
function destroyPath(path) {
|
|
2509
|
+
keysOf(pathStateLookup.value).forEach(key => {
|
|
2510
|
+
if (key.startsWith(path)) {
|
|
2511
|
+
delete pathStateLookup.value[key];
|
|
2489
2512
|
}
|
|
2490
2513
|
});
|
|
2514
|
+
pathStates.value = pathStates.value.filter(s => !s.path.startsWith(path));
|
|
2515
|
+
nextTick(() => {
|
|
2516
|
+
rebuildPathLookup();
|
|
2517
|
+
});
|
|
2491
2518
|
}
|
|
2492
2519
|
const formCtx = {
|
|
2493
2520
|
formId,
|
|
@@ -2514,6 +2541,10 @@ function useForm(opts) {
|
|
|
2514
2541
|
resetForm,
|
|
2515
2542
|
resetField,
|
|
2516
2543
|
handleSubmit,
|
|
2544
|
+
useFieldModel,
|
|
2545
|
+
defineInputBinds,
|
|
2546
|
+
defineComponentBinds: defineComponentBinds,
|
|
2547
|
+
defineField,
|
|
2517
2548
|
stageInitialValue,
|
|
2518
2549
|
unsetInitialValue,
|
|
2519
2550
|
setFieldInitialValue,
|
|
@@ -2523,7 +2554,7 @@ function useForm(opts) {
|
|
|
2523
2554
|
removePathState,
|
|
2524
2555
|
initialValues: initialValues,
|
|
2525
2556
|
getAllPathStates: () => pathStates.value,
|
|
2526
|
-
|
|
2557
|
+
destroyPath,
|
|
2527
2558
|
isFieldTouched,
|
|
2528
2559
|
isFieldDirty,
|
|
2529
2560
|
isFieldValid,
|
|
@@ -2622,7 +2653,7 @@ function useForm(opts) {
|
|
|
2622
2653
|
if (pathState) {
|
|
2623
2654
|
pathState.__flags.pendingReset = true;
|
|
2624
2655
|
}
|
|
2625
|
-
setFieldInitialValue(field, klona(newValue));
|
|
2656
|
+
setFieldInitialValue(field, klona(newValue), true);
|
|
2626
2657
|
setFieldValue(field, newValue, false);
|
|
2627
2658
|
setFieldTouched(field, (_a = state === null || state === void 0 ? void 0 : state.touched) !== null && _a !== void 0 ? _a : false);
|
|
2628
2659
|
setFieldError(field, (state === null || state === void 0 ? void 0 : state.errors) || []);
|
|
@@ -2636,8 +2667,9 @@ function useForm(opts) {
|
|
|
2636
2667
|
* Resets all fields
|
|
2637
2668
|
*/
|
|
2638
2669
|
function resetForm(resetState, opts) {
|
|
2639
|
-
let newValues = (resetState === null || resetState === void 0 ? void 0 : resetState.values) ? resetState.values : originalInitialValues.value;
|
|
2670
|
+
let newValues = klona((resetState === null || resetState === void 0 ? void 0 : resetState.values) ? resetState.values : originalInitialValues.value);
|
|
2640
2671
|
newValues = isTypedSchema(schema) && isCallable(schema.cast) ? schema.cast(newValues) : newValues;
|
|
2672
|
+
newValues = (opts === null || opts === void 0 ? void 0 : opts.force) ? newValues : merge(originalInitialValues.value, newValues);
|
|
2641
2673
|
setInitialValues(newValues);
|
|
2642
2674
|
mutateAllPathState(state => {
|
|
2643
2675
|
var _a;
|
|
@@ -2735,8 +2767,11 @@ function useForm(opts) {
|
|
|
2735
2767
|
setInPath(originalInitialValues.value, path, klona(value));
|
|
2736
2768
|
}
|
|
2737
2769
|
}
|
|
2738
|
-
function setFieldInitialValue(path, value) {
|
|
2770
|
+
function setFieldInitialValue(path, value, updateOriginal = false) {
|
|
2739
2771
|
setInPath(initialValues.value, path, klona(value));
|
|
2772
|
+
if (updateOriginal) {
|
|
2773
|
+
setInPath(originalInitialValues.value, path, klona(value));
|
|
2774
|
+
}
|
|
2740
2775
|
}
|
|
2741
2776
|
async function _validateSchema() {
|
|
2742
2777
|
const schemaValue = unref(schema);
|
|
@@ -2792,7 +2827,8 @@ function useForm(opts) {
|
|
|
2792
2827
|
});
|
|
2793
2828
|
}
|
|
2794
2829
|
function defineField(path, config) {
|
|
2795
|
-
const
|
|
2830
|
+
const label = isCallable(config) ? undefined : config === null || config === void 0 ? void 0 : config.label;
|
|
2831
|
+
const pathState = (findPathState(toValue(path)) || createPathState(path, { label }));
|
|
2796
2832
|
const evalConfig = () => (isCallable(config) ? config(omit(pathState, PRIVATE_PATH_STATE_KEYS)) : config || {});
|
|
2797
2833
|
function onBlur() {
|
|
2798
2834
|
var _a;
|
|
@@ -2834,10 +2870,54 @@ function useForm(opts) {
|
|
|
2834
2870
|
}
|
|
2835
2871
|
return base;
|
|
2836
2872
|
});
|
|
2837
|
-
|
|
2873
|
+
const model = createModel(path, () => { var _a; return (_a = evalConfig().validateOnModelUpdate) !== null && _a !== void 0 ? _a : true; });
|
|
2874
|
+
return [model, props];
|
|
2875
|
+
}
|
|
2876
|
+
function useFieldModel(pathOrPaths) {
|
|
2877
|
+
if (!Array.isArray(pathOrPaths)) {
|
|
2878
|
+
return createModel(pathOrPaths);
|
|
2879
|
+
}
|
|
2880
|
+
return pathOrPaths.map(p => createModel(p, true));
|
|
2881
|
+
}
|
|
2882
|
+
/**
|
|
2883
|
+
* @deprecated use defineField instead
|
|
2884
|
+
*/
|
|
2885
|
+
function defineInputBinds(path, config) {
|
|
2886
|
+
const [model, props] = defineField(path, config);
|
|
2887
|
+
function onBlur(e) {
|
|
2888
|
+
props.value.onBlur(e);
|
|
2889
|
+
}
|
|
2890
|
+
function onInput(e) {
|
|
2891
|
+
const value = normalizeEventValue(e);
|
|
2892
|
+
setFieldValue(toValue(path), value, false);
|
|
2893
|
+
props.value.onInput(e);
|
|
2894
|
+
}
|
|
2895
|
+
function onChange(e) {
|
|
2896
|
+
const value = normalizeEventValue(e);
|
|
2897
|
+
setFieldValue(toValue(path), value, false);
|
|
2898
|
+
props.value.onChange(e);
|
|
2899
|
+
}
|
|
2900
|
+
return computed(() => {
|
|
2901
|
+
return Object.assign(Object.assign({}, props.value), { onBlur,
|
|
2902
|
+
onInput,
|
|
2903
|
+
onChange, value: model.value });
|
|
2904
|
+
});
|
|
2905
|
+
}
|
|
2906
|
+
/**
|
|
2907
|
+
* @deprecated use defineField instead
|
|
2908
|
+
*/
|
|
2909
|
+
function defineComponentBinds(path, config) {
|
|
2910
|
+
const [model, props] = defineField(path, config);
|
|
2911
|
+
const pathState = findPathState(toValue(path));
|
|
2912
|
+
function onUpdateModelValue(value) {
|
|
2913
|
+
model.value = value;
|
|
2914
|
+
}
|
|
2915
|
+
return computed(() => {
|
|
2916
|
+
const conf = isCallable(config) ? config(omit(pathState, PRIVATE_PATH_STATE_KEYS)) : config || {};
|
|
2917
|
+
return Object.assign({ [conf.model || 'modelValue']: model.value, [`onUpdate:${conf.model || 'modelValue'}`]: onUpdateModelValue }, props.value);
|
|
2918
|
+
});
|
|
2838
2919
|
}
|
|
2839
|
-
return Object.assign(Object.assign({}, formCtx), { values: readonly(formValues), handleReset: () => resetForm(), submitForm
|
|
2840
|
-
defineField });
|
|
2920
|
+
return Object.assign(Object.assign({}, formCtx), { values: readonly(formValues), handleReset: () => resetForm(), submitForm });
|
|
2841
2921
|
}
|
|
2842
2922
|
/**
|
|
2843
2923
|
* Manages form meta aggregation
|
|
@@ -2875,7 +2955,6 @@ function useFormMeta(pathsState, currentValues, initialValues, errors) {
|
|
|
2875
2955
|
*/
|
|
2876
2956
|
function useFormInitialValues(pathsState, formValues, opts) {
|
|
2877
2957
|
const values = resolveInitialValues(opts);
|
|
2878
|
-
const providedValues = opts === null || opts === void 0 ? void 0 : opts.initialValues;
|
|
2879
2958
|
// these are the mutable initial values as the fields are mounted/unmounted
|
|
2880
2959
|
const initialValues = ref(values);
|
|
2881
2960
|
// these are the original initial value as provided by the user initially, they don't keep track of conditional fields
|
|
@@ -2903,21 +2982,21 @@ function useFormInitialValues(pathsState, formValues, opts) {
|
|
|
2903
2982
|
setInPath(formValues, state.path, klona(newValue));
|
|
2904
2983
|
});
|
|
2905
2984
|
}
|
|
2906
|
-
if (isRef(providedValues)) {
|
|
2907
|
-
watch(providedValues, value => {
|
|
2908
|
-
if (value) {
|
|
2909
|
-
setInitialValues(value, true);
|
|
2910
|
-
}
|
|
2911
|
-
}, {
|
|
2912
|
-
deep: true,
|
|
2913
|
-
});
|
|
2914
|
-
}
|
|
2915
2985
|
return {
|
|
2916
2986
|
initialValues,
|
|
2917
2987
|
originalInitialValues,
|
|
2918
2988
|
setInitialValues,
|
|
2919
2989
|
};
|
|
2920
2990
|
}
|
|
2991
|
+
function mergeValidationResults(a, b) {
|
|
2992
|
+
if (!b) {
|
|
2993
|
+
return a;
|
|
2994
|
+
}
|
|
2995
|
+
return {
|
|
2996
|
+
valid: a.valid && b.valid,
|
|
2997
|
+
errors: [...a.errors, ...b.errors],
|
|
2998
|
+
};
|
|
2999
|
+
}
|
|
2921
3000
|
|
|
2922
3001
|
const FormImpl = /** #__PURE__ */ defineComponent({
|
|
2923
3002
|
name: 'Form',
|
|
@@ -2961,12 +3040,11 @@ const FormImpl = /** #__PURE__ */ defineComponent({
|
|
|
2961
3040
|
},
|
|
2962
3041
|
},
|
|
2963
3042
|
setup(props, ctx) {
|
|
2964
|
-
const initialValues = toRef(props, 'initialValues');
|
|
2965
3043
|
const validationSchema = toRef(props, 'validationSchema');
|
|
2966
3044
|
const keepValues = toRef(props, 'keepValues');
|
|
2967
3045
|
const { errors, errorBag, values, meta, isSubmitting, isValidating, submitCount, controlledValues, validate, validateField, handleReset, resetForm, handleSubmit, setErrors, setFieldError, setFieldValue, setValues, setFieldTouched, setTouched, resetField, } = useForm({
|
|
2968
3046
|
validationSchema: validationSchema.value ? validationSchema : undefined,
|
|
2969
|
-
initialValues,
|
|
3047
|
+
initialValues: props.initialValues,
|
|
2970
3048
|
initialErrors: props.initialErrors,
|
|
2971
3049
|
initialTouched: props.initialTouched,
|
|
2972
3050
|
validateOnMount: props.validateOnMount,
|
|
@@ -3099,7 +3177,7 @@ function useFieldArray(arrayPath) {
|
|
|
3099
3177
|
}
|
|
3100
3178
|
let entryCounter = 0;
|
|
3101
3179
|
function getCurrentValues() {
|
|
3102
|
-
return getFromPath(form === null || form === void 0 ? void 0 : form.values,
|
|
3180
|
+
return getFromPath(form === null || form === void 0 ? void 0 : form.values, toValue(arrayPath), []) || [];
|
|
3103
3181
|
}
|
|
3104
3182
|
function initFields() {
|
|
3105
3183
|
const currentValues = getCurrentValues();
|
|
@@ -3130,7 +3208,7 @@ function useFieldArray(arrayPath) {
|
|
|
3130
3208
|
key,
|
|
3131
3209
|
value: computedDeep({
|
|
3132
3210
|
get() {
|
|
3133
|
-
const currentValues = getFromPath(form === null || form === void 0 ? void 0 : form.values,
|
|
3211
|
+
const currentValues = getFromPath(form === null || form === void 0 ? void 0 : form.values, toValue(arrayPath), []) || [];
|
|
3134
3212
|
const idx = fields.value.findIndex(e => e.key === key);
|
|
3135
3213
|
return idx === -1 ? value : currentValues[idx];
|
|
3136
3214
|
},
|
|
@@ -3144,7 +3222,7 @@ function useFieldArray(arrayPath) {
|
|
|
3144
3222
|
}
|
|
3145
3223
|
update(idx, value);
|
|
3146
3224
|
},
|
|
3147
|
-
}),
|
|
3225
|
+
}), // will be auto unwrapped
|
|
3148
3226
|
isFirst: false,
|
|
3149
3227
|
isLast: false,
|
|
3150
3228
|
};
|
|
@@ -3156,7 +3234,7 @@ function useFieldArray(arrayPath) {
|
|
|
3156
3234
|
form === null || form === void 0 ? void 0 : form.validate({ mode: 'silent' });
|
|
3157
3235
|
}
|
|
3158
3236
|
function remove(idx) {
|
|
3159
|
-
const pathName =
|
|
3237
|
+
const pathName = toValue(arrayPath);
|
|
3160
3238
|
const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
|
|
3161
3239
|
if (!pathValue || !Array.isArray(pathValue)) {
|
|
3162
3240
|
return;
|
|
@@ -3164,7 +3242,7 @@ function useFieldArray(arrayPath) {
|
|
|
3164
3242
|
const newValue = [...pathValue];
|
|
3165
3243
|
newValue.splice(idx, 1);
|
|
3166
3244
|
const fieldPath = pathName + `[${idx}]`;
|
|
3167
|
-
form.
|
|
3245
|
+
form.destroyPath(fieldPath);
|
|
3168
3246
|
form.unsetInitialValue(fieldPath);
|
|
3169
3247
|
setInPath(form.values, pathName, newValue);
|
|
3170
3248
|
fields.value.splice(idx, 1);
|
|
@@ -3172,7 +3250,7 @@ function useFieldArray(arrayPath) {
|
|
|
3172
3250
|
}
|
|
3173
3251
|
function push(initialValue) {
|
|
3174
3252
|
const value = klona(initialValue);
|
|
3175
|
-
const pathName =
|
|
3253
|
+
const pathName = toValue(arrayPath);
|
|
3176
3254
|
const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
|
|
3177
3255
|
const normalizedPathValue = isNullOrUndefined(pathValue) ? [] : pathValue;
|
|
3178
3256
|
if (!Array.isArray(normalizedPathValue)) {
|
|
@@ -3186,7 +3264,7 @@ function useFieldArray(arrayPath) {
|
|
|
3186
3264
|
afterMutation();
|
|
3187
3265
|
}
|
|
3188
3266
|
function swap(indexA, indexB) {
|
|
3189
|
-
const pathName =
|
|
3267
|
+
const pathName = toValue(arrayPath);
|
|
3190
3268
|
const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
|
|
3191
3269
|
if (!Array.isArray(pathValue) || !(indexA in pathValue) || !(indexB in pathValue)) {
|
|
3192
3270
|
return;
|
|
@@ -3206,7 +3284,7 @@ function useFieldArray(arrayPath) {
|
|
|
3206
3284
|
}
|
|
3207
3285
|
function insert(idx, initialValue) {
|
|
3208
3286
|
const value = klona(initialValue);
|
|
3209
|
-
const pathName =
|
|
3287
|
+
const pathName = toValue(arrayPath);
|
|
3210
3288
|
const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
|
|
3211
3289
|
if (!Array.isArray(pathValue) || pathValue.length < idx) {
|
|
3212
3290
|
return;
|
|
@@ -3220,14 +3298,14 @@ function useFieldArray(arrayPath) {
|
|
|
3220
3298
|
afterMutation();
|
|
3221
3299
|
}
|
|
3222
3300
|
function replace(arr) {
|
|
3223
|
-
const pathName =
|
|
3301
|
+
const pathName = toValue(arrayPath);
|
|
3224
3302
|
form.stageInitialValue(pathName, arr);
|
|
3225
3303
|
setInPath(form.values, pathName, arr);
|
|
3226
3304
|
initFields();
|
|
3227
3305
|
afterMutation();
|
|
3228
3306
|
}
|
|
3229
3307
|
function update(idx, value) {
|
|
3230
|
-
const pathName =
|
|
3308
|
+
const pathName = toValue(arrayPath);
|
|
3231
3309
|
const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
|
|
3232
3310
|
if (!Array.isArray(pathValue) || pathValue.length - 1 < idx) {
|
|
3233
3311
|
return;
|
|
@@ -3237,20 +3315,20 @@ function useFieldArray(arrayPath) {
|
|
|
3237
3315
|
}
|
|
3238
3316
|
function prepend(initialValue) {
|
|
3239
3317
|
const value = klona(initialValue);
|
|
3240
|
-
const pathName =
|
|
3318
|
+
const pathName = toValue(arrayPath);
|
|
3241
3319
|
const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
|
|
3242
3320
|
const normalizedPathValue = isNullOrUndefined(pathValue) ? [] : pathValue;
|
|
3243
3321
|
if (!Array.isArray(normalizedPathValue)) {
|
|
3244
3322
|
return;
|
|
3245
3323
|
}
|
|
3246
3324
|
const newValue = [value, ...normalizedPathValue];
|
|
3247
|
-
form.stageInitialValue(pathName + `[${newValue.length - 1}]`, value);
|
|
3248
3325
|
setInPath(form.values, pathName, newValue);
|
|
3326
|
+
form.stageInitialValue(pathName + `[0]`, value);
|
|
3249
3327
|
fields.value.unshift(createEntry(value));
|
|
3250
3328
|
afterMutation();
|
|
3251
3329
|
}
|
|
3252
3330
|
function move(oldIdx, newIdx) {
|
|
3253
|
-
const pathName =
|
|
3331
|
+
const pathName = toValue(arrayPath);
|
|
3254
3332
|
const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
|
|
3255
3333
|
const newValue = isNullOrUndefined(pathValue) ? [] : [...pathValue];
|
|
3256
3334
|
if (!Array.isArray(pathValue) || !(oldIdx in pathValue) || !(newIdx in pathValue)) {
|
|
@@ -3280,7 +3358,7 @@ function useFieldArray(arrayPath) {
|
|
|
3280
3358
|
};
|
|
3281
3359
|
form.fieldArrays.push(Object.assign({ path: arrayPath, reset: initFields }, fieldArrayCtx));
|
|
3282
3360
|
onBeforeUnmount(() => {
|
|
3283
|
-
const idx = form.fieldArrays.findIndex(i =>
|
|
3361
|
+
const idx = form.fieldArrays.findIndex(i => toValue(i.path) === toValue(arrayPath));
|
|
3284
3362
|
if (idx >= 0) {
|
|
3285
3363
|
form.fieldArrays.splice(idx, 1);
|
|
3286
3364
|
}
|
|
@@ -3307,7 +3385,7 @@ const FieldArrayImpl = /** #__PURE__ */ defineComponent({
|
|
|
3307
3385
|
},
|
|
3308
3386
|
},
|
|
3309
3387
|
setup(props, ctx) {
|
|
3310
|
-
const { push, remove, swap, insert, replace, update, prepend, move, fields } = useFieldArray(
|
|
3388
|
+
const { push, remove, swap, insert, replace, update, prepend, move, fields } = useFieldArray(() => props.name);
|
|
3311
3389
|
function slotProps() {
|
|
3312
3390
|
return {
|
|
3313
3391
|
fields: fields.value,
|
|
@@ -3772,4 +3850,4 @@ function useSetFormValues() {
|
|
|
3772
3850
|
return setFormValues;
|
|
3773
3851
|
}
|
|
3774
3852
|
|
|
3775
|
-
export { ErrorMessage, Field, FieldArray, FieldContextKey, Form, FormContextKey, IS_ABSENT, configure, defineRule, normalizeRules, useField, useFieldArray, useFieldError, useFieldValue, useForm, 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 };
|
|
3853
|
+
export { ErrorMessage, Field, FieldArray, FieldContextKey, Form, FormContextKey, IS_ABSENT, cleanupNonNestedPath, configure, defineRule, isNotNestedPath, normalizeRules, useField, useFieldArray, useFieldError, useFieldValue, useForm, 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 };
|