fix(FormItem): append a trigger field to the rule type (#5439)

pull/5449/head
bqy_fe 2022-04-06 16:11:26 +08:00 committed by GitHub
parent 7c6dcba441
commit dd0653249d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 29 deletions

View File

@ -13,7 +13,6 @@ import isEqual from 'lodash-es/isEqual';
import type { Options } from 'scroll-into-view-if-needed'; import type { Options } from 'scroll-into-view-if-needed';
import scrollIntoView from 'scroll-into-view-if-needed'; import scrollIntoView from 'scroll-into-view-if-needed';
import initDefaultProps from '../_util/props-util/initDefaultProps'; import initDefaultProps from '../_util/props-util/initDefaultProps';
import type { VueNode } from '../_util/type';
import { tuple } from '../_util/type'; import { tuple } from '../_util/type';
import type { ColProps } from '../grid/Col'; import type { ColProps } from '../grid/Col';
import type { import type {
@ -24,6 +23,7 @@ import type {
ValidateOptions, ValidateOptions,
Callbacks, Callbacks,
ValidateMessages, ValidateMessages,
Rule,
} from './interface'; } from './interface';
import { useInjectSize } from '../_util/hooks/useSize'; import { useInjectSize } from '../_util/hooks/useSize';
import useConfigInject from '../_util/hooks/useConfigInject'; import useConfigInject from '../_util/hooks/useConfigInject';
@ -34,32 +34,8 @@ import useForm from './useForm';
export type RequiredMark = boolean | 'optional'; export type RequiredMark = boolean | 'optional';
export type FormLayout = 'horizontal' | 'inline' | 'vertical'; export type FormLayout = 'horizontal' | 'inline' | 'vertical';
export type ValidationRule = { /** @deprecated Will warning in future branch. Pls use `Rule` instead. */
/** validation error message */ export type ValidationRule = Rule;
message?: VueNode;
/** built-in validation type, available options: https://github.com/yiminghe/async-validator#type */
type?: string;
/** indicates whether field is required */
required?: boolean;
/** treat required fields that only contain whitespace as errors */
whitespace?: boolean;
/** validate the exact length of a field */
len?: number;
/** validate the min length of a field */
min?: number;
/** validate the max length of a field */
max?: number;
/** validate the value from a list of possible values */
enum?: string | string[];
/** validate from a regular expression */
pattern?: RegExp;
/** transform a value before validation */
transform?: (value: any) => any;
/** custom validate function (Note: callback must be called) */
validator?: (rule: any, value: any, callback: any, source?: any, options?: any) => any;
trigger?: string;
};
export const formProps = () => ({ export const formProps = () => ({
layout: PropTypes.oneOf(tuple('horizontal', 'inline', 'vertical')), layout: PropTypes.oneOf(tuple('horizontal', 'inline', 'vertical')),
@ -73,7 +49,7 @@ export const formProps = () => ({
/** @deprecated Will warning in future branch. Pls use `requiredMark` instead. */ /** @deprecated Will warning in future branch. Pls use `requiredMark` instead. */
hideRequiredMark: { type: Boolean, default: undefined }, hideRequiredMark: { type: Boolean, default: undefined },
model: PropTypes.object, model: PropTypes.object,
rules: { type: Object as PropType<{ [k: string]: ValidationRule[] | ValidationRule }> }, rules: { type: Object as PropType<{ [k: string]: Rule[] | Rule }> },
validateMessages: { validateMessages: {
type: Object as PropType<ValidateMessages>, type: Object as PropType<ValidateMessages>,
default: undefined as ValidateMessages, default: undefined as ValidateMessages,

View File

@ -52,24 +52,36 @@ type Validator = (
export interface ValidatorRule { export interface ValidatorRule {
warningOnly?: boolean; warningOnly?: boolean;
message?: string | VueNode; message?: string | VueNode;
/** custom validate function (Note: callback must be called) */
validator: Validator; validator: Validator;
} }
interface BaseRule { interface BaseRule {
warningOnly?: boolean; warningOnly?: boolean;
/** validate the value from a list of possible values */
enum?: StoreValue[]; enum?: StoreValue[];
/** validate the exact length of a field */
len?: number; len?: number;
/** validate the max length of a field */
max?: number; max?: number;
/** validation error message */
message?: string | VueNode; message?: string | VueNode;
/** validate the min length of a field */
min?: number; min?: number;
/** validate from a regular expression */
pattern?: RegExp; pattern?: RegExp;
/** indicates whether field is required */
required?: boolean; required?: boolean;
/** transform a value before validation */
transform?: (value: StoreValue) => StoreValue; transform?: (value: StoreValue) => StoreValue;
/** built-in validation type, available options: https://github.com/yiminghe/async-validator#type */
type?: RuleType; type?: RuleType;
/** treat required fields that only contain whitespace as errors */
whitespace?: boolean; whitespace?: boolean;
/** Customize rule level `validateTrigger`. Must be subset of Field `validateTrigger` */ /** Customize rule level `validateTrigger`. Must be subset of Field `validateTrigger` */
validateTrigger?: string | string[]; validateTrigger?: string | string[];
/** Check trigger timing */
trigger?: 'blur' | 'change' | ['change', 'blur'];
} }
type AggregationRule = BaseRule & Partial<ValidatorRule>; type AggregationRule = BaseRule & Partial<ValidatorRule>;