fix: form validateMessages not work
parent
5ce268846b
commit
e66a35e1f2
|
@ -145,7 +145,12 @@ const Form = defineComponent({
|
|||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
const validateMessages = computed(() => {
|
||||
return {
|
||||
...defaultValidateMessages,
|
||||
...props.validateMessages,
|
||||
};
|
||||
});
|
||||
const formClassName = computed(() =>
|
||||
classNames(prefixCls.value, {
|
||||
[`${prefixCls.value}-${props.layout}`]: true,
|
||||
|
@ -267,10 +272,7 @@ const Form = defineComponent({
|
|||
// Add field validate rule in to promise list
|
||||
if (!provideNameList || containsNamePath(namePathList, fieldNamePath)) {
|
||||
const promise = field.validateRules({
|
||||
validateMessages: {
|
||||
...defaultValidateMessages,
|
||||
...props.validateMessages,
|
||||
},
|
||||
validateMessages: validateMessages.value,
|
||||
...options,
|
||||
});
|
||||
|
||||
|
@ -376,6 +378,7 @@ const Form = defineComponent({
|
|||
onValidate: (name, status, errors) => {
|
||||
emit('validate', name, status, errors);
|
||||
},
|
||||
validateMessages,
|
||||
});
|
||||
|
||||
watch(
|
||||
|
|
|
@ -186,9 +186,20 @@ export default defineComponent({
|
|||
watchEffect(() => {
|
||||
validateState.value = props.validateStatus;
|
||||
});
|
||||
|
||||
const messageVariables = computed(() => {
|
||||
let variables: Record<string, string> = {};
|
||||
if (typeof props.label === 'string') {
|
||||
variables.label = props.label;
|
||||
} else if (props.name) {
|
||||
variables.label = String(name);
|
||||
}
|
||||
if (props.messageVariables) {
|
||||
variables = { ...variables, ...props.messageVariables };
|
||||
}
|
||||
return variables;
|
||||
});
|
||||
const validateRules = (options: ValidateOptions) => {
|
||||
const { validateFirst = false, messageVariables } = props;
|
||||
const { validateFirst = false } = props;
|
||||
const { triggerName } = options || {};
|
||||
|
||||
let filteredRules = rulesRef.value;
|
||||
|
@ -209,9 +220,12 @@ export default defineComponent({
|
|||
namePath.value,
|
||||
fieldValue.value,
|
||||
filteredRules as RuleObject[],
|
||||
options,
|
||||
{
|
||||
validateMessages: formContext.validateMessages.value,
|
||||
...options,
|
||||
},
|
||||
validateFirst,
|
||||
messageVariables,
|
||||
messageVariables.value,
|
||||
);
|
||||
validateState.value = 'validating';
|
||||
errors.value = [];
|
||||
|
|
|
@ -3,7 +3,8 @@ import { inject, provide, computed } from 'vue';
|
|||
import type { ColProps } from '../grid';
|
||||
import type { RequiredMark, ValidationRule } from './Form';
|
||||
import type { ValidateStatus, FieldExpose } from './FormItem';
|
||||
import type { FormLabelAlign } from './interface';
|
||||
import type { FormLabelAlign, ValidateMessages } from './interface';
|
||||
import { defaultValidateMessages } from './utils/messages';
|
||||
|
||||
export interface FormContextProps {
|
||||
model?: ComputedRef<any>;
|
||||
|
@ -24,6 +25,7 @@ export interface FormContextProps {
|
|||
status: boolean,
|
||||
errors: string[] | null,
|
||||
) => void;
|
||||
validateMessages: ComputedRef<ValidateMessages>;
|
||||
}
|
||||
|
||||
export const FormContextKey: InjectionKey<FormContextProps> = Symbol('formContextKey');
|
||||
|
@ -44,6 +46,7 @@ export const useInjectForm = () => {
|
|||
rules: computed(() => undefined),
|
||||
requiredMark: computed(() => false),
|
||||
onValidate: () => {},
|
||||
validateMessages: computed(() => defaultValidateMessages),
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue