fix: global form message not work, close #5693

pull/5702/head
tangjinzhou 2022-06-11 21:56:41 +08:00
parent 171b2b643f
commit e5b9308374
2 changed files with 5 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import type { ExtractPropTypes, InjectionKey, PropType, Ref } from 'vue';
import { inject, provide } from 'vue';
import { computed, inject, provide } from 'vue';
import type { ValidateMessages } from '../form/interface';
import type { RequiredMark } from '../form/Form';
import type { RenderEmptyHandler } from './renderEmpty';
@ -17,7 +17,7 @@ export const useProvideGlobalForm = (state: GlobalFormCOntextProps) => {
};
export const useInjectGlobalForm = () => {
return inject(GlobalFormContextKey, {});
return inject(GlobalFormContextKey, { validateMessages: computed(() => undefined) });
};
export const GlobalConfigContextKey: InjectionKey<GlobalFormCOntextProps> =

View File

@ -30,6 +30,7 @@ import useConfigInject from '../_util/hooks/useConfigInject';
import { useProvideForm } from './context';
import type { SizeType } from '../config-provider';
import useForm from './useForm';
import { useInjectGlobalForm } from '../config-provider/context';
export type RequiredMark = boolean | 'optional';
export type FormLayout = 'horizontal' | 'inline' | 'vertical';
@ -127,10 +128,11 @@ const Form = defineComponent({
return true;
});
const mergedColon = computed(() => props.colon ?? contextForm.value?.colon);
const { validateMessages: globalValidateMessages } = useInjectGlobalForm();
const validateMessages = computed(() => {
return {
...defaultValidateMessages,
...contextForm.value?.validateMessages,
...globalValidateMessages.value,
...props.validateMessages,
};
});