fix: global form message not work, close #5693
parent
171b2b643f
commit
e5b9308374
|
@ -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> =
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue