From f7e7ce9d4fdf87de11995e7990d56e6da929addc Mon Sep 17 00:00:00 2001 From: Han Date: Wed, 5 Feb 2020 21:44:49 -0500 Subject: [PATCH] fix: Minor fix on ValidationRule to match AsyncValidator (#21250) * Minor fix on ValidationRule to match AsyncValidator * update doc --- components/form/Form.tsx | 23 ++++++++++++++++++++--- components/form/index.en-US.md | 2 +- components/form/index.zh-CN.md | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/components/form/Form.tsx b/components/form/Form.tsx index ab20c54fce..2c33ef044e 100755 --- a/components/form/Form.tsx +++ b/components/form/Form.tsx @@ -29,7 +29,7 @@ export interface FormCreateOption { } const FormLayouts = tuple('horizontal', 'inline', 'vertical'); -export type FormLayout = (typeof FormLayouts)[number]; +export type FormLayout = typeof FormLayouts[number]; export interface FormProps extends React.FormHTMLAttributes { layout?: FormLayout; @@ -51,11 +51,28 @@ export interface FormProps extends React.FormHTMLAttributes { labelAlign?: FormLabelAlign; } +export type ValidationRuleType = + | 'string' + | 'number' + | 'boolean' + | 'method' + | 'regexp' + | 'integer' + | 'float' + | 'array' + | 'object' + | 'enum' + | 'date' + | 'url' + | 'hex' + | 'email' + | 'any'; + export type ValidationRule = { /** validation error message */ message?: React.ReactNode; /** built-in validation type, available options: https://github.com/yiminghe/async-validator#type */ - type?: string; + type?: ValidationRuleType; /** indicates whether field is required */ required?: boolean; /** treat required fields that only contain whitespace as errors */ @@ -67,7 +84,7 @@ export type ValidationRule = { /** validate the max length of a field */ max?: number; /** validate the value from a list of possible values */ - enum?: string | string[]; + enum?: (string | number | boolean)[]; /** validate from a regular expression */ pattern?: RegExp; /** transform a value before validation */ diff --git a/components/form/index.en-US.md b/components/form/index.en-US.md index a003ed97cf..4bfb80cf00 100644 --- a/components/form/index.en-US.md +++ b/components/form/index.en-US.md @@ -210,7 +210,7 @@ Note: if Form.Item has multiple children that had been decorated by `getFieldDec | Property | Description | Type | Default Value | Version | | --- | --- | --- | --- | --- | -| enum | validate a value from a list of possible values | string | - | | +| enum | validate a value from a list of possible values | string[] | - | | | len | validate an exact length of a field | number | - | | | max | validate a max length of a field | number | - | | | message | validation error message | string\|ReactNode | - | | diff --git a/components/form/index.zh-CN.md b/components/form/index.zh-CN.md index 2286630a72..5598556fc4 100644 --- a/components/form/index.zh-CN.md +++ b/components/form/index.zh-CN.md @@ -212,7 +212,7 @@ validateFields(['field1', 'field2'], options, (errors, values) => { | 参数 | 说明 | 类型 | 默认值 | 版本 | | --- | --- | --- | --- | --- | -| enum | 枚举类型 | string | - | | +| enum | 枚举类型 | string[] | - | | | len | 字段长度 | number | - | | | max | 最大长度 | number | - | | | message | 校验文案 | string\|ReactNode | - | |