From 64befeda32ab4c2edda822424f5aa0e2a857124b Mon Sep 17 00:00:00 2001 From: "mitchell.demler" Date: Mon, 22 May 2017 15:57:09 +1200 Subject: [PATCH] Add ValidationRule type for getFieldDecorator validation rules Copied types from english documentation. (these might need checking?) --- components/form/Form.tsx | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/components/form/Form.tsx b/components/form/Form.tsx index 24e4d3c3a..8bf5f2675 100755 --- a/components/form/Form.tsx +++ b/components/form/Form.tsx @@ -30,6 +30,31 @@ export interface FormProps { hideRequiredMark?: boolean; } +export type ValidationRule = { + /** validation error message */ + message?: string; + /** 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) => any; +}; + export type ValidateCallback = (erros: any, values: any) => void; // function create @@ -74,7 +99,7 @@ export type WrappedFormUtils = { /** 校验子节点值的时机 */ validateTrigger?: string | string[]; /** 校验规则,参见 [async-validator](https://github.com/yiminghe/async-validator) */ - rules?: Array; + rules?: ValidationRule[]; /** 是否和其他控件互斥,特别用于 Radio 单选控件 */ exclusive?: boolean; }): (node: React.ReactNode) => React.ReactNode;