fix(basicForm): Fixed an issue where custom rules trigger would not take effect (#2439)
Co-authored-by: 吴安乐 <wuanle@qimao.com>
| | |
| | | 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', |
| | |
| | | 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((_) => {}); |
| | | } |
| | |
| | | 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: { |
| | |
| | | } |
| | | 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<typeof defineComponent>; |