vee-validate 4.6.10 → 4.7.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 +46 -39
- package/dist/vee-validate.esm.js +169 -187
- package/dist/vee-validate.js +168 -186
- package/dist/vee-validate.min.js +2 -2
- package/package.json +2 -2
package/dist/vee-validate.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* vee-validate v4.
|
|
2
|
+
* vee-validate v4.7.1
|
|
3
3
|
* (c) 2022 Abdelrahman Awad
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { getCurrentInstance, inject, warn as warn$1, ref, watch, unref, computed, reactive, onUnmounted, nextTick, onMounted, provide, isRef, onBeforeUnmount, defineComponent, toRef, resolveDynamicComponent, h, watchEffect, markRaw } from 'vue';
|
|
7
7
|
import { setupDevtoolsPlugin } from '@vue/devtools-api';
|
|
8
8
|
|
|
9
9
|
function isCallable(fn) {
|
|
@@ -225,50 +225,59 @@ function isFile(a) {
|
|
|
225
225
|
return a instanceof File;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
|
236
|
-
if (a.constructor !== b.constructor) return false;
|
|
237
|
-
|
|
238
|
-
var length, i, keys;
|
|
239
|
-
if (Array.isArray(a)) {
|
|
240
|
-
length = a.length;
|
|
241
|
-
if (length != b.length) return false;
|
|
242
|
-
for (i = length; i-- !== 0;)
|
|
243
|
-
if (!equal(a[i], b[i])) return false;
|
|
244
|
-
return true;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
|
250
|
-
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
|
251
|
-
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
|
228
|
+
function set(obj, key, val) {
|
|
229
|
+
if (typeof val.value === 'object') val.value = klona(val.value);
|
|
230
|
+
if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === '__proto__') {
|
|
231
|
+
Object.defineProperty(obj, key, val);
|
|
232
|
+
} else obj[key] = val.value;
|
|
233
|
+
}
|
|
252
234
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
if (length !== Object.keys(b).length) return false;
|
|
235
|
+
function klona(x) {
|
|
236
|
+
if (typeof x !== 'object') return x;
|
|
256
237
|
|
|
257
|
-
|
|
258
|
-
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
238
|
+
var i=0, k, list, tmp, str=Object.prototype.toString.call(x);
|
|
259
239
|
|
|
260
|
-
|
|
261
|
-
|
|
240
|
+
if (str === '[object Object]') {
|
|
241
|
+
tmp = Object.create(x.__proto__ || null);
|
|
242
|
+
} else if (str === '[object Array]') {
|
|
243
|
+
tmp = Array(x.length);
|
|
244
|
+
} else if (str === '[object Set]') {
|
|
245
|
+
tmp = new Set;
|
|
246
|
+
x.forEach(function (val) {
|
|
247
|
+
tmp.add(klona(val));
|
|
248
|
+
});
|
|
249
|
+
} else if (str === '[object Map]') {
|
|
250
|
+
tmp = new Map;
|
|
251
|
+
x.forEach(function (val, key) {
|
|
252
|
+
tmp.set(klona(key), klona(val));
|
|
253
|
+
});
|
|
254
|
+
} else if (str === '[object Date]') {
|
|
255
|
+
tmp = new Date(+x);
|
|
256
|
+
} else if (str === '[object RegExp]') {
|
|
257
|
+
tmp = new RegExp(x.source, x.flags);
|
|
258
|
+
} else if (str === '[object DataView]') {
|
|
259
|
+
tmp = new x.constructor( klona(x.buffer) );
|
|
260
|
+
} else if (str === '[object ArrayBuffer]') {
|
|
261
|
+
tmp = x.slice(0);
|
|
262
|
+
} else if (str.slice(-6) === 'Array]') {
|
|
263
|
+
// ArrayBuffer.isView(x)
|
|
264
|
+
// ~> `new` bcuz `Buffer.slice` => ref
|
|
265
|
+
tmp = new x.constructor(x);
|
|
266
|
+
}
|
|
262
267
|
|
|
263
|
-
|
|
264
|
-
|
|
268
|
+
if (tmp) {
|
|
269
|
+
for (list=Object.getOwnPropertySymbols(x); i < list.length; i++) {
|
|
270
|
+
set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
|
|
271
|
+
}
|
|
265
272
|
|
|
266
|
-
|
|
267
|
-
|
|
273
|
+
for (i=0, list=Object.getOwnPropertyNames(x); i < list.length; i++) {
|
|
274
|
+
if (Object.hasOwnProperty.call(tmp, k=list[i]) && tmp[k] === x[k]) continue;
|
|
275
|
+
set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
268
278
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
};
|
|
279
|
+
return tmp || x;
|
|
280
|
+
}
|
|
272
281
|
|
|
273
282
|
function cleanupNonNestedPath(path) {
|
|
274
283
|
if (isNotNestedPath(path)) {
|
|
@@ -391,11 +400,11 @@ function resolveNextCheckboxValue(currentValue, checkedValue, uncheckedValue) {
|
|
|
391
400
|
if (Array.isArray(currentValue)) {
|
|
392
401
|
const newVal = [...currentValue];
|
|
393
402
|
// Use isEqual since checked object values can possibly fail the equality check #3883
|
|
394
|
-
const idx = newVal.findIndex(v =>
|
|
403
|
+
const idx = newVal.findIndex(v => isEqual(v, checkedValue));
|
|
395
404
|
idx >= 0 ? newVal.splice(idx, 1) : newVal.push(checkedValue);
|
|
396
405
|
return newVal;
|
|
397
406
|
}
|
|
398
|
-
return
|
|
407
|
+
return isEqual(currentValue, checkedValue) ? uncheckedValue : checkedValue;
|
|
399
408
|
}
|
|
400
409
|
/**
|
|
401
410
|
* Creates a throttled function that only invokes the provided function (`func`) at most once per within a given number of milliseconds
|
|
@@ -455,6 +464,26 @@ function withLatest(fn, onDone) {
|
|
|
455
464
|
onDone(result, args);
|
|
456
465
|
return result;
|
|
457
466
|
};
|
|
467
|
+
}
|
|
468
|
+
function computedDeep({ get, set }) {
|
|
469
|
+
const baseRef = ref(klona(get()));
|
|
470
|
+
watch(get, newValue => {
|
|
471
|
+
if (isEqual(newValue, baseRef.value)) {
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
baseRef.value = klona(newValue);
|
|
475
|
+
}, {
|
|
476
|
+
deep: true,
|
|
477
|
+
});
|
|
478
|
+
watch(baseRef, newValue => {
|
|
479
|
+
if (isEqual(newValue, get())) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
set(klona(newValue));
|
|
483
|
+
}, {
|
|
484
|
+
deep: true,
|
|
485
|
+
});
|
|
486
|
+
return baseRef;
|
|
458
487
|
}
|
|
459
488
|
|
|
460
489
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -844,64 +873,10 @@ async function validateObjectSchema(schema, values, opts) {
|
|
|
844
873
|
};
|
|
845
874
|
}
|
|
846
875
|
|
|
847
|
-
function set(obj, key, val) {
|
|
848
|
-
if (typeof val.value === 'object') val.value = klona(val.value);
|
|
849
|
-
if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === '__proto__') {
|
|
850
|
-
Object.defineProperty(obj, key, val);
|
|
851
|
-
} else obj[key] = val.value;
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
function klona(x) {
|
|
855
|
-
if (typeof x !== 'object') return x;
|
|
856
|
-
|
|
857
|
-
var i=0, k, list, tmp, str=Object.prototype.toString.call(x);
|
|
858
|
-
|
|
859
|
-
if (str === '[object Object]') {
|
|
860
|
-
tmp = Object.create(x.__proto__ || null);
|
|
861
|
-
} else if (str === '[object Array]') {
|
|
862
|
-
tmp = Array(x.length);
|
|
863
|
-
} else if (str === '[object Set]') {
|
|
864
|
-
tmp = new Set;
|
|
865
|
-
x.forEach(function (val) {
|
|
866
|
-
tmp.add(klona(val));
|
|
867
|
-
});
|
|
868
|
-
} else if (str === '[object Map]') {
|
|
869
|
-
tmp = new Map;
|
|
870
|
-
x.forEach(function (val, key) {
|
|
871
|
-
tmp.set(klona(key), klona(val));
|
|
872
|
-
});
|
|
873
|
-
} else if (str === '[object Date]') {
|
|
874
|
-
tmp = new Date(+x);
|
|
875
|
-
} else if (str === '[object RegExp]') {
|
|
876
|
-
tmp = new RegExp(x.source, x.flags);
|
|
877
|
-
} else if (str === '[object DataView]') {
|
|
878
|
-
tmp = new x.constructor( klona(x.buffer) );
|
|
879
|
-
} else if (str === '[object ArrayBuffer]') {
|
|
880
|
-
tmp = x.slice(0);
|
|
881
|
-
} else if (str.slice(-6) === 'Array]') {
|
|
882
|
-
// ArrayBuffer.isView(x)
|
|
883
|
-
// ~> `new` bcuz `Buffer.slice` => ref
|
|
884
|
-
tmp = new x.constructor(x);
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
if (tmp) {
|
|
888
|
-
for (list=Object.getOwnPropertySymbols(x); i < list.length; i++) {
|
|
889
|
-
set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
for (i=0, list=Object.getOwnPropertyNames(x); i < list.length; i++) {
|
|
893
|
-
if (Object.hasOwnProperty.call(tmp, k=list[i]) && tmp[k] === x[k]) continue;
|
|
894
|
-
set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
return tmp || x;
|
|
899
|
-
}
|
|
900
|
-
|
|
901
876
|
let ID_COUNTER = 0;
|
|
902
877
|
function useFieldState(path, init) {
|
|
903
|
-
const { value, initialValue, setInitialValue } = _useFieldValue(path, init.modelValue,
|
|
904
|
-
const { errorMessage, errors, setErrors } = _useFieldErrors(path,
|
|
878
|
+
const { value, initialValue, setInitialValue } = _useFieldValue(path, init.modelValue, init.form);
|
|
879
|
+
const { errorMessage, errors, setErrors } = _useFieldErrors(path, init.form);
|
|
905
880
|
const meta = _useFieldMeta(value, initialValue, errors);
|
|
906
881
|
const id = ID_COUNTER >= Number.MAX_SAFE_INTEGER ? 0 : ++ID_COUNTER;
|
|
907
882
|
function setState(state) {
|
|
@@ -933,8 +908,7 @@ function useFieldState(path, init) {
|
|
|
933
908
|
/**
|
|
934
909
|
* Creates the field value and resolves the initial value
|
|
935
910
|
*/
|
|
936
|
-
function _useFieldValue(path, modelValue,
|
|
937
|
-
const form = shouldInjectForm === true ? injectWithSelf(FormContextKey, undefined) : undefined;
|
|
911
|
+
function _useFieldValue(path, modelValue, form) {
|
|
938
912
|
const modelRef = ref(unref(modelValue));
|
|
939
913
|
function resolveInitialValue() {
|
|
940
914
|
if (!form) {
|
|
@@ -1005,8 +979,7 @@ function _useFieldMeta(currentValue, initialValue, errors) {
|
|
|
1005
979
|
/**
|
|
1006
980
|
* Creates the error message state for the field state
|
|
1007
981
|
*/
|
|
1008
|
-
function _useFieldErrors(path,
|
|
1009
|
-
const form = shouldInjectForm ? injectWithSelf(FormContextKey, undefined) : undefined;
|
|
982
|
+
function _useFieldErrors(path, form) {
|
|
1010
983
|
function normalizeErrors(messages) {
|
|
1011
984
|
if (!messages) {
|
|
1012
985
|
return [];
|
|
@@ -1403,13 +1376,14 @@ function useField(name, rules, opts) {
|
|
|
1403
1376
|
return _useField(name, rules, opts);
|
|
1404
1377
|
}
|
|
1405
1378
|
function _useField(name, rules, opts) {
|
|
1406
|
-
const { initialValue: modelValue, validateOnMount, bails, type, checkedValue, label, validateOnValueUpdate, uncheckedValue,
|
|
1407
|
-
const
|
|
1379
|
+
const { initialValue: modelValue, validateOnMount, bails, type, checkedValue, label, validateOnValueUpdate, uncheckedValue, controlled, keepValueOnUnmount, modelPropName, syncVModel, form: controlForm, } = normalizeOptions(unref(name), opts);
|
|
1380
|
+
const injectedForm = controlled ? injectWithSelf(FormContextKey) : undefined;
|
|
1381
|
+
const form = controlForm || injectedForm;
|
|
1408
1382
|
// a flag indicating if the field is about to be removed/unmounted.
|
|
1409
1383
|
let markedForRemoval = false;
|
|
1410
1384
|
const { id, value, initialValue, meta, setState, errors, errorMessage } = useFieldState(name, {
|
|
1411
1385
|
modelValue,
|
|
1412
|
-
|
|
1386
|
+
form,
|
|
1413
1387
|
});
|
|
1414
1388
|
if (syncVModel) {
|
|
1415
1389
|
useVModel({ value, prop: modelPropName, handleChange });
|
|
@@ -1626,20 +1600,20 @@ function normalizeOptions(name, opts) {
|
|
|
1626
1600
|
initialValue: undefined,
|
|
1627
1601
|
validateOnMount: false,
|
|
1628
1602
|
bails: true,
|
|
1629
|
-
rules: '',
|
|
1630
1603
|
label: name,
|
|
1631
1604
|
validateOnValueUpdate: true,
|
|
1632
|
-
standalone: false,
|
|
1633
1605
|
keepValueOnUnmount: undefined,
|
|
1634
1606
|
modelPropName: 'modelValue',
|
|
1635
1607
|
syncVModel: true,
|
|
1608
|
+
controlled: true,
|
|
1636
1609
|
});
|
|
1637
1610
|
if (!opts) {
|
|
1638
1611
|
return defaults();
|
|
1639
1612
|
}
|
|
1640
1613
|
// TODO: Deprecate this in next major release
|
|
1641
1614
|
const checkedValue = 'valueProp' in opts ? opts.valueProp : opts.checkedValue;
|
|
1642
|
-
|
|
1615
|
+
const controlled = 'standalone' in opts ? !opts.standalone : opts.controlled;
|
|
1616
|
+
return Object.assign(Object.assign(Object.assign({}, defaults()), (opts || {})), { controlled: controlled !== null && controlled !== void 0 ? controlled : true, checkedValue });
|
|
1643
1617
|
}
|
|
1644
1618
|
/**
|
|
1645
1619
|
* Extracts the validation rules from a schema
|
|
@@ -1910,6 +1884,7 @@ let FORM_COUNTER = 0;
|
|
|
1910
1884
|
function useForm(opts) {
|
|
1911
1885
|
var _a;
|
|
1912
1886
|
const formId = FORM_COUNTER++;
|
|
1887
|
+
const controlledModelPaths = new Set();
|
|
1913
1888
|
// Prevents fields from double resetting their values, which causes checkboxes to toggle their initial value
|
|
1914
1889
|
// TODO: This won't be needed if we centralize all the state inside the `form` for form inputs
|
|
1915
1890
|
let RESET_LOCK = false;
|
|
@@ -1972,6 +1947,13 @@ function useForm(opts) {
|
|
|
1972
1947
|
const { initialValues, originalInitialValues, setInitialValues } = useFormInitialValues(fieldsByPath, formValues, opts === null || opts === void 0 ? void 0 : opts.initialValues);
|
|
1973
1948
|
// form meta aggregations
|
|
1974
1949
|
const meta = useFormMeta(fieldsByPath, formValues, originalInitialValues, errors);
|
|
1950
|
+
const controlledValues = computed(() => {
|
|
1951
|
+
return [...controlledModelPaths, ...keysOf(fieldsByPath.value)].reduce((acc, path) => {
|
|
1952
|
+
const value = getFromPath(formValues, path);
|
|
1953
|
+
setInPath(acc, path, value);
|
|
1954
|
+
return acc;
|
|
1955
|
+
}, {});
|
|
1956
|
+
});
|
|
1975
1957
|
const schema = opts === null || opts === void 0 ? void 0 : opts.validationSchema;
|
|
1976
1958
|
/**
|
|
1977
1959
|
* Batches validation runs in 5ms batches
|
|
@@ -2021,10 +2003,65 @@ function useForm(opts) {
|
|
|
2021
2003
|
return validation;
|
|
2022
2004
|
}, { valid: formResult.valid, results: {}, errors: {} });
|
|
2023
2005
|
});
|
|
2006
|
+
function makeSubmissionFactory(onlyControlled) {
|
|
2007
|
+
return function submitHandlerFactory(fn, onValidationError) {
|
|
2008
|
+
return function submissionHandler(e) {
|
|
2009
|
+
if (e instanceof Event) {
|
|
2010
|
+
e.preventDefault();
|
|
2011
|
+
e.stopPropagation();
|
|
2012
|
+
}
|
|
2013
|
+
// Touch all fields
|
|
2014
|
+
setTouched(keysOf(fieldsByPath.value).reduce((acc, field) => {
|
|
2015
|
+
acc[field] = true;
|
|
2016
|
+
return acc;
|
|
2017
|
+
}, {}));
|
|
2018
|
+
isSubmitting.value = true;
|
|
2019
|
+
submitCount.value++;
|
|
2020
|
+
return validate()
|
|
2021
|
+
.then(result => {
|
|
2022
|
+
const values = klona(formValues);
|
|
2023
|
+
if (result.valid && typeof fn === 'function') {
|
|
2024
|
+
const controlled = klona(controlledValues.value);
|
|
2025
|
+
return fn(onlyControlled ? controlled : values, {
|
|
2026
|
+
evt: e,
|
|
2027
|
+
controlledValues: controlled,
|
|
2028
|
+
setErrors,
|
|
2029
|
+
setFieldError,
|
|
2030
|
+
setTouched,
|
|
2031
|
+
setFieldTouched,
|
|
2032
|
+
setValues,
|
|
2033
|
+
setFieldValue,
|
|
2034
|
+
resetForm,
|
|
2035
|
+
});
|
|
2036
|
+
}
|
|
2037
|
+
if (!result.valid && typeof onValidationError === 'function') {
|
|
2038
|
+
onValidationError({
|
|
2039
|
+
values,
|
|
2040
|
+
evt: e,
|
|
2041
|
+
errors: result.errors,
|
|
2042
|
+
results: result.results,
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
})
|
|
2046
|
+
.then(returnVal => {
|
|
2047
|
+
isSubmitting.value = false;
|
|
2048
|
+
return returnVal;
|
|
2049
|
+
}, err => {
|
|
2050
|
+
isSubmitting.value = false;
|
|
2051
|
+
// re-throw the err so it doesn't go silent
|
|
2052
|
+
throw err;
|
|
2053
|
+
});
|
|
2054
|
+
};
|
|
2055
|
+
};
|
|
2056
|
+
}
|
|
2057
|
+
const handleSubmitImpl = makeSubmissionFactory(false);
|
|
2058
|
+
const handleSubmit = handleSubmitImpl;
|
|
2059
|
+
handleSubmit.withControlled = makeSubmissionFactory(true);
|
|
2024
2060
|
const formCtx = {
|
|
2025
2061
|
formId,
|
|
2026
2062
|
fieldsByPath,
|
|
2027
2063
|
values: formValues,
|
|
2064
|
+
controlledValues,
|
|
2028
2065
|
errorBag,
|
|
2029
2066
|
errors,
|
|
2030
2067
|
schema,
|
|
@@ -2123,7 +2160,7 @@ function useForm(opts) {
|
|
|
2123
2160
|
fieldArrays.forEach(f => f && f.reset());
|
|
2124
2161
|
}
|
|
2125
2162
|
function createModel(path) {
|
|
2126
|
-
const { value } = _useFieldValue(path);
|
|
2163
|
+
const { value } = _useFieldValue(path, undefined, formCtx);
|
|
2127
2164
|
watch(value, () => {
|
|
2128
2165
|
if (!fieldExists(unref(path))) {
|
|
2129
2166
|
validate({ mode: 'validated-only' });
|
|
@@ -2131,6 +2168,7 @@ function useForm(opts) {
|
|
|
2131
2168
|
}, {
|
|
2132
2169
|
deep: true,
|
|
2133
2170
|
});
|
|
2171
|
+
controlledModelPaths.add(unref(path));
|
|
2134
2172
|
return value;
|
|
2135
2173
|
}
|
|
2136
2174
|
function useFieldModel(path) {
|
|
@@ -2275,12 +2313,18 @@ function useForm(opts) {
|
|
|
2275
2313
|
// This used to be handled in the useField composable but the form has better context on when it should/not happen.
|
|
2276
2314
|
// if it does belong to it that means the group still exists
|
|
2277
2315
|
// #3844
|
|
2278
|
-
if (isSameGroup &&
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2316
|
+
if (isSameGroup && !shouldKeepValue) {
|
|
2317
|
+
if (Array.isArray(currentGroupValue)) {
|
|
2318
|
+
const valueIdx = currentGroupValue.findIndex(i => isEqual(i, unref(field.checkedValue)));
|
|
2319
|
+
if (valueIdx > -1) {
|
|
2320
|
+
const newVal = [...currentGroupValue];
|
|
2321
|
+
newVal.splice(valueIdx, 1);
|
|
2322
|
+
setFieldValue(fieldName, newVal, { force: true });
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
else if (currentGroupValue === unref(field.checkedValue)) {
|
|
2326
|
+
// Remove field if it is a group but does not have an array value, like for radio inputs #3963
|
|
2327
|
+
unsetPath(formValues, fieldName);
|
|
2284
2328
|
}
|
|
2285
2329
|
}
|
|
2286
2330
|
// Field was removed entirely, we should unset its path
|
|
@@ -2293,7 +2337,8 @@ function useForm(opts) {
|
|
|
2293
2337
|
if (shouldKeepValue) {
|
|
2294
2338
|
return;
|
|
2295
2339
|
}
|
|
2296
|
-
|
|
2340
|
+
// Don't apply emptyContainer check unless the current group value is an array
|
|
2341
|
+
if (isGroup && Array.isArray(currentGroupValue) && !isEmptyContainer(currentGroupValue)) {
|
|
2297
2342
|
return;
|
|
2298
2343
|
}
|
|
2299
2344
|
unsetPath(formValues, fieldName);
|
|
@@ -2347,55 +2392,6 @@ function useForm(opts) {
|
|
|
2347
2392
|
}
|
|
2348
2393
|
return fieldInstance.validate();
|
|
2349
2394
|
}
|
|
2350
|
-
function handleSubmit(fn, onValidationError) {
|
|
2351
|
-
return function submissionHandler(e) {
|
|
2352
|
-
if (e instanceof Event) {
|
|
2353
|
-
e.preventDefault();
|
|
2354
|
-
e.stopPropagation();
|
|
2355
|
-
}
|
|
2356
|
-
// Touch all fields
|
|
2357
|
-
setTouched(keysOf(fieldsByPath.value).reduce((acc, field) => {
|
|
2358
|
-
acc[field] = true;
|
|
2359
|
-
return acc;
|
|
2360
|
-
}, {}));
|
|
2361
|
-
isSubmitting.value = true;
|
|
2362
|
-
submitCount.value++;
|
|
2363
|
-
return validate()
|
|
2364
|
-
.then(result => {
|
|
2365
|
-
if (result.valid && typeof fn === 'function') {
|
|
2366
|
-
return fn(klona(formValues), {
|
|
2367
|
-
evt: e,
|
|
2368
|
-
setErrors,
|
|
2369
|
-
setFieldError,
|
|
2370
|
-
setTouched,
|
|
2371
|
-
setFieldTouched,
|
|
2372
|
-
setValues,
|
|
2373
|
-
setFieldValue,
|
|
2374
|
-
resetForm,
|
|
2375
|
-
});
|
|
2376
|
-
}
|
|
2377
|
-
if (!result.valid && typeof onValidationError === 'function') {
|
|
2378
|
-
onValidationError({
|
|
2379
|
-
values: klona(formValues),
|
|
2380
|
-
evt: e,
|
|
2381
|
-
errors: result.errors,
|
|
2382
|
-
results: result.results,
|
|
2383
|
-
});
|
|
2384
|
-
}
|
|
2385
|
-
})
|
|
2386
|
-
.then(returnVal => {
|
|
2387
|
-
isSubmitting.value = false;
|
|
2388
|
-
return returnVal;
|
|
2389
|
-
}, err => {
|
|
2390
|
-
isSubmitting.value = false;
|
|
2391
|
-
// re-throw the err so it doesn't go silent
|
|
2392
|
-
throw err;
|
|
2393
|
-
});
|
|
2394
|
-
};
|
|
2395
|
-
}
|
|
2396
|
-
function setFieldInitialValue(path, value) {
|
|
2397
|
-
setInPath(initialValues.value, path, klona(value));
|
|
2398
|
-
}
|
|
2399
2395
|
function unsetInitialValue(path) {
|
|
2400
2396
|
unsetPath(initialValues.value, path);
|
|
2401
2397
|
}
|
|
@@ -2409,6 +2405,9 @@ function useForm(opts) {
|
|
|
2409
2405
|
setInPath(originalInitialValues.value, path, klona(value));
|
|
2410
2406
|
}
|
|
2411
2407
|
}
|
|
2408
|
+
function setFieldInitialValue(path, value) {
|
|
2409
|
+
setInPath(initialValues.value, path, klona(value));
|
|
2410
|
+
}
|
|
2412
2411
|
async function _validateSchema() {
|
|
2413
2412
|
const schemaValue = unref(schema);
|
|
2414
2413
|
if (!schemaValue) {
|
|
@@ -2460,26 +2459,7 @@ function useForm(opts) {
|
|
|
2460
2459
|
deep: true,
|
|
2461
2460
|
});
|
|
2462
2461
|
}
|
|
2463
|
-
return {
|
|
2464
|
-
errors,
|
|
2465
|
-
meta,
|
|
2466
|
-
values: formValues,
|
|
2467
|
-
isSubmitting,
|
|
2468
|
-
submitCount,
|
|
2469
|
-
validate,
|
|
2470
|
-
validateField,
|
|
2471
|
-
handleReset: () => resetForm(),
|
|
2472
|
-
resetForm,
|
|
2473
|
-
handleSubmit,
|
|
2474
|
-
submitForm,
|
|
2475
|
-
setFieldError,
|
|
2476
|
-
setErrors,
|
|
2477
|
-
setFieldValue,
|
|
2478
|
-
setValues,
|
|
2479
|
-
setFieldTouched,
|
|
2480
|
-
setTouched,
|
|
2481
|
-
useFieldModel,
|
|
2482
|
-
};
|
|
2462
|
+
return Object.assign(Object.assign({}, formCtx), { handleReset: () => resetForm(), submitForm });
|
|
2483
2463
|
}
|
|
2484
2464
|
/**
|
|
2485
2465
|
* Manages form meta aggregation
|
|
@@ -2639,7 +2619,7 @@ const FormImpl = defineComponent({
|
|
|
2639
2619
|
const initialValues = toRef(props, 'initialValues');
|
|
2640
2620
|
const validationSchema = toRef(props, 'validationSchema');
|
|
2641
2621
|
const keepValues = toRef(props, 'keepValues');
|
|
2642
|
-
const { errors, values, meta, isSubmitting, submitCount, validate, validateField, handleReset, resetForm, handleSubmit, setErrors, setFieldError, setFieldValue, setValues, setFieldTouched, setTouched, } = useForm({
|
|
2622
|
+
const { errors, values, meta, isSubmitting, submitCount, controlledValues, validate, validateField, handleReset, resetForm, handleSubmit, setErrors, setFieldError, setFieldValue, setValues, setFieldTouched, setTouched, } = useForm({
|
|
2643
2623
|
validationSchema: validationSchema.value ? validationSchema : undefined,
|
|
2644
2624
|
initialValues,
|
|
2645
2625
|
initialErrors: props.initialErrors,
|
|
@@ -2674,6 +2654,7 @@ const FormImpl = defineComponent({
|
|
|
2674
2654
|
values: values,
|
|
2675
2655
|
isSubmitting: isSubmitting.value,
|
|
2676
2656
|
submitCount: submitCount.value,
|
|
2657
|
+
controlledValues: controlledValues.value,
|
|
2677
2658
|
validate,
|
|
2678
2659
|
validateField,
|
|
2679
2660
|
handleSubmit: handleScopedSlotSubmit,
|
|
@@ -2767,7 +2748,7 @@ function useFieldArray(arrayPath) {
|
|
|
2767
2748
|
const key = entryCounter++;
|
|
2768
2749
|
const entry = {
|
|
2769
2750
|
key,
|
|
2770
|
-
value:
|
|
2751
|
+
value: computedDeep({
|
|
2771
2752
|
get() {
|
|
2772
2753
|
const currentValues = getFromPath(form === null || form === void 0 ? void 0 : form.values, unref(arrayPath), []) || [];
|
|
2773
2754
|
const idx = fields.value.findIndex(e => e.key === key);
|
|
@@ -2859,6 +2840,7 @@ function useFieldArray(arrayPath) {
|
|
|
2859
2840
|
return;
|
|
2860
2841
|
}
|
|
2861
2842
|
form === null || form === void 0 ? void 0 : form.setFieldValue(`${pathName}[${idx}]`, value);
|
|
2843
|
+
form === null || form === void 0 ? void 0 : form.validate({ mode: 'validated-only' });
|
|
2862
2844
|
}
|
|
2863
2845
|
function prepend(value) {
|
|
2864
2846
|
const pathName = unref(arrayPath);
|