From 39bf296b7ae494a0ae339573338e6e37997caa94 Mon Sep 17 00:00:00 2001 From: varHarrie Date: Wed, 22 Apr 2020 11:52:24 +0800 Subject: [PATCH 1/2] feat: form-model add validateMessages prop (#2130) close #2130 --- components/form-model/Form.jsx | 1 + components/form-model/FormItem.jsx | 3 +++ types/form-model/form.d.ts | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/components/form-model/Form.jsx b/components/form-model/Form.jsx index 0be2b74be..de6fcdcdd 100755 --- a/components/form-model/Form.jsx +++ b/components/form-model/Form.jsx @@ -17,6 +17,7 @@ export const FormProps = { hideRequiredMark: PropTypes.bool, model: PropTypes.object, rules: PropTypes.object, + validateMessages: PropTypes.any, validateOnRuleChange: PropTypes.bool, }; diff --git a/components/form-model/FormItem.jsx b/components/form-model/FormItem.jsx index 9dfba0ff7..bbd1a6778 100644 --- a/components/form-model/FormItem.jsx +++ b/components/form-model/FormItem.jsx @@ -142,6 +142,9 @@ export default { } descriptor[this.prop] = rules; const validator = new AsyncValidator(descriptor); + if (this.FormContext && this.FormContext.validateMessages) { + validator.messages(this.FormContext.validateMessages); + } const model = {}; model[this.prop] = this.fieldValue; validator.validate(model, { firstFields: true }, (errors, invalidFields) => { diff --git a/types/form-model/form.d.ts b/types/form-model/form.d.ts index f8654813e..6e13e810c 100644 --- a/types/form-model/form.d.ts +++ b/types/form-model/form.d.ts @@ -132,8 +132,14 @@ export declare class FormModel extends AntdComponent { * validation rules of form * @type object */ - rules: object; + + /** + * Default validate message. And its format is similar with newMessages's returned value + * @type any + */ + validateMessages?: any; + /** * whether to trigger validation when the rules prop is changed * @type Boolean From 18ca95d0313643229eb2eac4988c02848cdcae41 Mon Sep 17 00:00:00 2001 From: Baran Date: Wed, 22 Apr 2020 14:57:36 +0800 Subject: [PATCH 2/2] feat: add createForm return ts type (#2116) --- types/form/form.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/form/form.d.ts b/types/form/form.d.ts index 9c98ab851..8967cde48 100644 --- a/types/form/form.d.ts +++ b/types/form/form.d.ts @@ -389,7 +389,7 @@ export declare class Form extends AntdComponent { */ options: object; - createForm(context: Vue, options?: IformCreateOption): any; + createForm(context: Vue, options?: IformCreateOption): WrappedFormUtils; /** * Convert props to field value