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); }