Skip to content

Commit f7a4d13

Browse files
authored
fix: fixed arguments of callbacks in formApi (vbenjs#5970)
* 修复 `handleValuesChange` 传递的参数不是处理后的表单值的问题 * 修复 `handleReset` 未能传递正确参数的问题
1 parent 0936861 commit f7a4d13

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

docs/src/components/common-ui/vben-form.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ useVbenForm 返回的第二个参数,是一个对象,包含了一些表单
327327

328328
::: tip handleValuesChange
329329

330-
`handleValuesChange` 回调函数的第一个参数`values`装载了表单改变后的当前值对象,第二个参数`fieldsChanged`是一个数组,包含了所有被改变的字段名。注意:第二个参数仅在v5.5.4(不含)以上版本可用。
330+
`handleValuesChange` 回调函数的第一个参数`values`装载了表单改变后的当前值对象,第二个参数`fieldsChanged`是一个数组,包含了所有被改变的字段名。注意:第二个参数仅在v5.5.4(不含)以上版本可用,并且传递的是已在schema中定义的字段名。如果你使用了字段映射并且需要检查是哪些字段发生了变化的话,请注意该参数并不会包含映射后的字段名
331331

332332
:::
333333

packages/@core/ui-kit/form-ui/src/components/form-actions.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async function handleReset(e: Event) {
6262
e?.stopPropagation();
6363
const props = unref(rootProps);
6464
65-
const values = toRaw(props.formApi?.getValues());
65+
const values = toRaw(await props.formApi?.getValues());
6666
6767
if (isFunction(props.handleReset)) {
6868
await props.handleReset?.(values);

packages/@core/ui-kit/form-ui/src/vben-use-form.vue

+5-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ onMounted(async () => {
7272
await nextTick();
7373
watch(
7474
() => form.values,
75-
(newVal) => {
75+
async (newVal) => {
7676
if (forward.value.handleValuesChange) {
7777
const fields = state.value.schema?.map((item) => {
7878
return item.fieldName;
@@ -91,7 +91,10 @@ onMounted(async () => {
9191
9292
if (changedFields.length > 0) {
9393
// 调用handleValuesChange回调,传入所有表单值的深拷贝和变更的字段列表
94-
forward.value.handleValuesChange(cloneDeep(newVal), changedFields);
94+
forward.value.handleValuesChange(
95+
cloneDeep(await forward.value.formApi.getValues()),
96+
changedFields,
97+
);
9598
}
9699
}
97100
}

0 commit comments

Comments
 (0)