feat: form-model add validateMessages prop (#2130)

close #2130
pull/2133/head
varHarrie 2020-04-22 11:52:24 +08:00 committed by GitHub
parent bf52f73c5c
commit 39bf296b7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View File

@ -17,6 +17,7 @@ export const FormProps = {
hideRequiredMark: PropTypes.bool,
model: PropTypes.object,
rules: PropTypes.object,
validateMessages: PropTypes.any,
validateOnRuleChange: PropTypes.bool,
};

View File

@ -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) => {

View File

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