fix: fixed arguments of callbacks in formApi
(#5970)
* 修复 `handleValuesChange` 传递的参数不是处理后的表单值的问题 * 修复 `handleReset` 未能传递正确参数的问题
This commit is contained in:
parent
0936861da1
commit
f7a4d13a4c
@ -327,7 +327,7 @@ useVbenForm 返回的第二个参数,是一个对象,包含了一些表单
|
|||||||
|
|
||||||
::: tip handleValuesChange
|
::: tip handleValuesChange
|
||||||
|
|
||||||
`handleValuesChange` 回调函数的第一个参数`values`装载了表单改变后的当前值对象,第二个参数`fieldsChanged`是一个数组,包含了所有被改变的字段名。注意:第二个参数仅在v5.5.4(不含)以上版本可用。
|
`handleValuesChange` 回调函数的第一个参数`values`装载了表单改变后的当前值对象,第二个参数`fieldsChanged`是一个数组,包含了所有被改变的字段名。注意:第二个参数仅在v5.5.4(不含)以上版本可用,并且传递的是已在schema中定义的字段名。如果你使用了字段映射并且需要检查是哪些字段发生了变化的话,请注意该参数并不会包含映射后的字段名。
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ async function handleReset(e: Event) {
|
|||||||
e?.stopPropagation();
|
e?.stopPropagation();
|
||||||
const props = unref(rootProps);
|
const props = unref(rootProps);
|
||||||
|
|
||||||
const values = toRaw(props.formApi?.getValues());
|
const values = toRaw(await props.formApi?.getValues());
|
||||||
|
|
||||||
if (isFunction(props.handleReset)) {
|
if (isFunction(props.handleReset)) {
|
||||||
await props.handleReset?.(values);
|
await props.handleReset?.(values);
|
||||||
|
@ -72,7 +72,7 @@ onMounted(async () => {
|
|||||||
await nextTick();
|
await nextTick();
|
||||||
watch(
|
watch(
|
||||||
() => form.values,
|
() => form.values,
|
||||||
(newVal) => {
|
async (newVal) => {
|
||||||
if (forward.value.handleValuesChange) {
|
if (forward.value.handleValuesChange) {
|
||||||
const fields = state.value.schema?.map((item) => {
|
const fields = state.value.schema?.map((item) => {
|
||||||
return item.fieldName;
|
return item.fieldName;
|
||||||
@ -91,7 +91,10 @@ onMounted(async () => {
|
|||||||
|
|
||||||
if (changedFields.length > 0) {
|
if (changedFields.length > 0) {
|
||||||
// 调用handleValuesChange回调,传入所有表单值的深拷贝和变更的字段列表
|
// 调用handleValuesChange回调,传入所有表单值的深拷贝和变更的字段列表
|
||||||
forward.value.handleValuesChange(cloneDeep(newVal), changedFields);
|
forward.value.handleValuesChange(
|
||||||
|
cloneDeep(await forward.value.formApi.getValues()),
|
||||||
|
changedFields,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user