Skip to content

Commit dd06532

Browse files
authored
fix(FormItem): append a trigger field to the rule type (#5439)
1 parent 7c6dcba commit dd06532

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

components/form/Form.tsx

+4-28
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import isEqual from 'lodash-es/isEqual';
1313
import type { Options } from 'scroll-into-view-if-needed';
1414
import scrollIntoView from 'scroll-into-view-if-needed';
1515
import initDefaultProps from '../_util/props-util/initDefaultProps';
16-
import type { VueNode } from '../_util/type';
1716
import { tuple } from '../_util/type';
1817
import type { ColProps } from '../grid/Col';
1918
import type {
@@ -24,6 +23,7 @@ import type {
2423
ValidateOptions,
2524
Callbacks,
2625
ValidateMessages,
26+
Rule,
2727
} from './interface';
2828
import { useInjectSize } from '../_util/hooks/useSize';
2929
import useConfigInject from '../_util/hooks/useConfigInject';
@@ -34,32 +34,8 @@ import useForm from './useForm';
3434
export type RequiredMark = boolean | 'optional';
3535
export type FormLayout = 'horizontal' | 'inline' | 'vertical';
3636

37-
export type ValidationRule = {
38-
/** validation error message */
39-
message?: VueNode;
40-
/** built-in validation type, available options: https://github.com/yiminghe/async-validator#type */
41-
type?: string;
42-
/** indicates whether field is required */
43-
required?: boolean;
44-
/** treat required fields that only contain whitespace as errors */
45-
whitespace?: boolean;
46-
/** validate the exact length of a field */
47-
len?: number;
48-
/** validate the min length of a field */
49-
min?: number;
50-
/** validate the max length of a field */
51-
max?: number;
52-
/** validate the value from a list of possible values */
53-
enum?: string | string[];
54-
/** validate from a regular expression */
55-
pattern?: RegExp;
56-
/** transform a value before validation */
57-
transform?: (value: any) => any;
58-
/** custom validate function (Note: callback must be called) */
59-
validator?: (rule: any, value: any, callback: any, source?: any, options?: any) => any;
60-
61-
trigger?: string;
62-
};
37+
/** @deprecated Will warning in future branch. Pls use `Rule` instead. */
38+
export type ValidationRule = Rule;
6339

6440
export const formProps = () => ({
6541
layout: PropTypes.oneOf(tuple('horizontal', 'inline', 'vertical')),
@@ -73,7 +49,7 @@ export const formProps = () => ({
7349
/** @deprecated Will warning in future branch. Pls use `requiredMark` instead. */
7450
hideRequiredMark: { type: Boolean, default: undefined },
7551
model: PropTypes.object,
76-
rules: { type: Object as PropType<{ [k: string]: ValidationRule[] | ValidationRule }> },
52+
rules: { type: Object as PropType<{ [k: string]: Rule[] | Rule }> },
7753
validateMessages: {
7854
type: Object as PropType<ValidateMessages>,
7955
default: undefined as ValidateMessages,

components/form/interface.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,36 @@ type Validator = (
5252
export interface ValidatorRule {
5353
warningOnly?: boolean;
5454
message?: string | VueNode;
55+
/** custom validate function (Note: callback must be called) */
5556
validator: Validator;
5657
}
5758

5859
interface BaseRule {
5960
warningOnly?: boolean;
61+
/** validate the value from a list of possible values */
6062
enum?: StoreValue[];
63+
/** validate the exact length of a field */
6164
len?: number;
65+
/** validate the max length of a field */
6266
max?: number;
67+
/** validation error message */
6368
message?: string | VueNode;
69+
/** validate the min length of a field */
6470
min?: number;
71+
/** validate from a regular expression */
6572
pattern?: RegExp;
73+
/** indicates whether field is required */
6674
required?: boolean;
75+
/** transform a value before validation */
6776
transform?: (value: StoreValue) => StoreValue;
77+
/** built-in validation type, available options: https://github.com/yiminghe/async-validator#type */
6878
type?: RuleType;
79+
/** treat required fields that only contain whitespace as errors */
6980
whitespace?: boolean;
70-
7181
/** Customize rule level `validateTrigger`. Must be subset of Field `validateTrigger` */
7282
validateTrigger?: string | string[];
83+
/** Check trigger timing */
84+
trigger?: 'blur' | 'change' | ['change', 'blur'];
7385
}
7486

7587
type AggregationRule = BaseRule & Partial<ValidatorRule>;

0 commit comments

Comments
 (0)