From fe58af2e78fe134f1ab90b513a96b4dee7042d81 Mon Sep 17 00:00:00 2001 From: ryomahan Date: Sun, 17 Nov 2024 21:04:35 +0800 Subject: [PATCH] fix: form-api.setValues can't resolve nested fields (#4915) fix #4912 --- packages/@core/ui-kit/form-ui/src/form-api.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/@core/ui-kit/form-ui/src/form-api.ts b/packages/@core/ui-kit/form-ui/src/form-api.ts index ebd2f736..07de5d75 100644 --- a/packages/@core/ui-kit/form-ui/src/form-api.ts +++ b/packages/@core/ui-kit/form-ui/src/form-api.ts @@ -13,13 +13,13 @@ import { toRaw } from 'vue'; import { Store } from '@vben-core/shared/store'; import { bindMethods, + createMerge, isFunction, + isObject, mergeWithArrayOverride, StateHandler, } from '@vben-core/shared/utils'; -import { objectPick } from '@vueuse/core'; - function getDefaultState(): VbenFormProps { return { actionWrapperClass: '', @@ -250,8 +250,17 @@ export class FormApi { form.setValues(fields, shouldValidate); return; } - const fieldNames = this.state?.schema?.map((item) => item.fieldName) ?? []; - const filteredFields = objectPick(fields, fieldNames); + + const fieldMergeFn = createMerge((obj, key, value) => { + if (key in obj) { + obj[key] = + !Array.isArray(obj[key]) && isObject(obj[key]) + ? fieldMergeFn(obj[key], value) + : value; + } + return true; + }); + const filteredFields = fieldMergeFn(fields, form.values); form.setValues(filteredFields, shouldValidate); }