Browse Source

fix: Minor fix on ValidationRule to match AsyncValidator (#21250)

* Minor fix on ValidationRule to match AsyncValidator

* update doc
pull/21265/head
Han 5 years ago
committed by GitHub
parent
commit
f7e7ce9d4f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      components/form/Form.tsx
  2. 2
      components/form/index.en-US.md
  3. 2
      components/form/index.zh-CN.md

23
components/form/Form.tsx

@ -29,7 +29,7 @@ export interface FormCreateOption<T> {
}
const FormLayouts = tuple('horizontal', 'inline', 'vertical');
export type FormLayout = (typeof FormLayouts)[number];
export type FormLayout = typeof FormLayouts[number];
export interface FormProps extends React.FormHTMLAttributes<HTMLFormElement> {
layout?: FormLayout;
@ -51,11 +51,28 @@ export interface FormProps extends React.FormHTMLAttributes<HTMLFormElement> {
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 */

2
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 | - | |

2
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 | - | |

Loading…
Cancel
Save