From c7639c490944419a0312a95d5f0375b37d8fee44 Mon Sep 17 00:00:00 2001 From: Little-LittleProgrammer <56573480+Little-LittleProgrammer@users.noreply.github.com> Date: Wed, 7 Dec 2022 17:11:42 +0800 Subject: [PATCH] fix(basicForm): Fixed an issue where custom rules trigger would not take effect (#2439) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 吴安乐 --- src/components/Form/src/BasicForm.vue | 6 +++++- src/components/Form/src/components/FormItem.vue | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/Form/src/BasicForm.vue b/src/components/Form/src/BasicForm.vue index 5f3724222..d9844721e 100644 --- a/src/components/Form/src/BasicForm.vue +++ b/src/components/Form/src/BasicForm.vue @@ -64,6 +64,7 @@ import { basicProps } from './props'; import { useDesign } from '/@/hooks/web/useDesign'; import { cloneDeep } from 'lodash-es'; + import { isFunction, isArray } from '/@/utils/is'; export default defineComponent({ name: 'BasicForm', @@ -242,9 +243,12 @@ propsRef.value = deepMerge(unref(propsRef) || {}, formProps); } - function setFormModel(key: string, value: any) { + function setFormModel(key: string, value: any, schema: FormSchema) { formModel[key] = value; const { validateTrigger } = unref(getBindValue); + if (isFunction(schema.dynamicRules) || isArray(schema.rules)) { + return; + } if (!validateTrigger || validateTrigger === 'change') { validateFields([key]).catch((_) => {}); } diff --git a/src/components/Form/src/components/FormItem.vue b/src/components/Form/src/components/FormItem.vue index 45297b64c..8ce579ab9 100644 --- a/src/components/Form/src/components/FormItem.vue +++ b/src/components/Form/src/components/FormItem.vue @@ -35,7 +35,7 @@ default: () => ({}), }, setFormModel: { - type: Function as PropType<(key: string, value: any) => void>, + type: Function as PropType<(key: string, value: any, schema: FormSchema) => void>, default: null, }, tableAction: { @@ -253,7 +253,7 @@ } const target = e ? e.target : null; const value = target ? (isCheck ? target.checked : target.value) : e; - props.setFormModel(field, value); + props.setFormModel(field, value, props.schema); }, }; const Comp = componentMap.get(component) as ReturnType;