Skip to content

Commit e5b9308

Browse files
committed
fix: global form message not work, close vueComponent#5693
1 parent 171b2b6 commit e5b9308

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

components/config-provider/context.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ExtractPropTypes, InjectionKey, PropType, Ref } from 'vue';
2-
import { inject, provide } from 'vue';
2+
import { computed, inject, provide } from 'vue';
33
import type { ValidateMessages } from '../form/interface';
44
import type { RequiredMark } from '../form/Form';
55
import type { RenderEmptyHandler } from './renderEmpty';
@@ -17,7 +17,7 @@ export const useProvideGlobalForm = (state: GlobalFormCOntextProps) => {
1717
};
1818

1919
export const useInjectGlobalForm = () => {
20-
return inject(GlobalFormContextKey, {});
20+
return inject(GlobalFormContextKey, { validateMessages: computed(() => undefined) });
2121
};
2222

2323
export const GlobalConfigContextKey: InjectionKey<GlobalFormCOntextProps> =

components/form/Form.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import useConfigInject from '../_util/hooks/useConfigInject';
3030
import { useProvideForm } from './context';
3131
import type { SizeType } from '../config-provider';
3232
import useForm from './useForm';
33+
import { useInjectGlobalForm } from '../config-provider/context';
3334

3435
export type RequiredMark = boolean | 'optional';
3536
export type FormLayout = 'horizontal' | 'inline' | 'vertical';
@@ -127,10 +128,11 @@ const Form = defineComponent({
127128
return true;
128129
});
129130
const mergedColon = computed(() => props.colon ?? contextForm.value?.colon);
131+
const { validateMessages: globalValidateMessages } = useInjectGlobalForm();
130132
const validateMessages = computed(() => {
131133
return {
132134
...defaultValidateMessages,
133-
...contextForm.value?.validateMessages,
135+
...globalValidateMessages.value,
134136
...props.validateMessages,
135137
};
136138
});

0 commit comments

Comments
 (0)