Skip to content

Commit

Permalink
fix(Form): rule bug
Browse files Browse the repository at this point in the history
  • Loading branch information
deot committed Mar 1, 2022
1 parent 9cddf3b commit c1f7c97
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/form/form-item-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,25 @@ export default {
this.$on('form-change', this.handleFieldChange);
},
getRules() {
let formRules = this.form.rules;
const selfRules = this.rules;

// getPropByPath(formRules, this.prop.replace(/\.[0-9]+\./g, '.'));
formRules = formRules ? formRules[this.prop] : [];
return cloneDeep([].concat(selfRules || formRules || []));
const formRules = this.form.rules;
const formItemBindRules = this.rules instanceof Array
? this.rules
: this.rules
? [this.rules]
: undefined;

let formItemRules = formItemBindRules || [];
if (!formItemRules.length) {
try {
// 如果是数组的话 xxx.1.xxx -> xxx.xxx
let { value } = getPropByPath(formRules, this.prop.replace(/\.[0-9]+\./g, '.')) || {};
formItemRules = value || [];
} catch {
formItemRules = formRules ? formRules[this.prop] : [];
}
}

return cloneDeep(formItemRules);
},
getFilteredRule(trigger) {
const rules = this.getRules();
Expand Down

0 comments on commit c1f7c97

Please sign in to comment.