Commit c7639c490944419a0312a95d5f0375b37d8fee44

Authored by Little-LittleProgrammer
Committed by GitHub
1 parent 6af82826

fix(basicForm): Fixed an issue where custom rules trigger would not take effect (#2439)

Co-authored-by: 吴安乐 <wuanle@qimao.com>
src/components/Form/src/BasicForm.vue
... ... @@ -64,6 +64,7 @@
64 64 import { basicProps } from './props';
65 65 import { useDesign } from '/@/hooks/web/useDesign';
66 66 import { cloneDeep } from 'lodash-es';
  67 + import { isFunction, isArray } from '/@/utils/is';
67 68  
68 69 export default defineComponent({
69 70 name: 'BasicForm',
... ... @@ -242,9 +243,12 @@
242 243 propsRef.value = deepMerge(unref(propsRef) || {}, formProps);
243 244 }
244 245  
245   - function setFormModel(key: string, value: any) {
  246 + function setFormModel(key: string, value: any, schema: FormSchema) {
246 247 formModel[key] = value;
247 248 const { validateTrigger } = unref(getBindValue);
  249 + if (isFunction(schema.dynamicRules) || isArray(schema.rules)) {
  250 + return;
  251 + }
248 252 if (!validateTrigger || validateTrigger === 'change') {
249 253 validateFields([key]).catch((_) => {});
250 254 }
... ...
src/components/Form/src/components/FormItem.vue
... ... @@ -35,7 +35,7 @@
35 35 default: () => ({}),
36 36 },
37 37 setFormModel: {
38   - type: Function as PropType<(key: string, value: any) => void>,
  38 + type: Function as PropType<(key: string, value: any, schema: FormSchema) => void>,
39 39 default: null,
40 40 },
41 41 tableAction: {
... ... @@ -253,7 +253,7 @@
253 253 }
254 254 const target = e ? e.target : null;
255 255 const value = target ? (isCheck ? target.checked : target.value) : e;
256   - props.setFormModel(field, value);
  256 + props.setFormModel(field, value, props.schema);
257 257 },
258 258 };
259 259 const Comp = componentMap.get(component) as ReturnType<typeof defineComponent>;
... ...