Skip to content

Commit

Permalink
fix(validate): auto clear errorMsg
Browse files Browse the repository at this point in the history
  • Loading branch information
Genuifx committed Mar 3, 2020
1 parent 8f7a71f commit 1792e87
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/wxa-validate/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ export default (options = {}) => {
console.error(e);
}

this.$clearErrorMsg(name);
let errorMap = {
...this.data.$form.errMap,
...$errMap,
};
// console.log('校验规则', rule, '校验值', value, '非法', invalid)
this.setData({
'$form.dirty': true,
[`$form.valid.${name}`]: !invalid,
Expand All @@ -115,6 +117,7 @@ export default (options = {}) => {
};

vm.$validateAll = function (except = '') {
let exceptRule = Array.isArray(except) ? except : [except];
return new Promise((resolve, reject) => {
let q = wx.createSelectorQuery();

Expand All @@ -125,15 +128,18 @@ export default (options = {}) => {
dataset: true,
id: true,
properties: ['value'],
}, (res) => {
}, async (res) => {
if (res == null || res.length === 0) {
reject('没有找到类名为wxa-input的Input组件');
}
let tasks = [];
for (let {value, dataset} of res) {
if (dataset.name === except) break;
this.$validate({currentTarget: {dataset}, detail: {value}})
if (~exceptRule.indexOf(dataset.name)) break;
tasks.push(this.$validate({currentTarget: {dataset}, detail: {value}}))
}
let valid = !this.data.$form.errMsgs.length;
await Promise.all(tasks);

let valid = !(this.data.$form.errMsgs && this.data.$form.errMsgs.length);
resolve({valid, ...res});
})
.exec()
Expand Down

0 comments on commit 1792e87

Please sign in to comment.