Skip to content

feat: form-model add validateMessages prop #2130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/form-model/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const FormProps = {
hideRequiredMark: PropTypes.bool,
model: PropTypes.object,
rules: PropTypes.object,
validateMessages: PropTypes.any,
validateOnRuleChange: PropTypes.bool,
};

Expand Down
3 changes: 3 additions & 0 deletions components/form-model/FormItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
8 changes: 7 additions & 1 deletion types/form-model/form.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down