Commit 476d1c4f authored by Allenice's avatar Allenice Committed by 杨奕

Form: fix async validate bug

parent 0c47e6d3
......@@ -80,7 +80,19 @@
console.warn('[Element Warn][Form]model is required for validate to work!');
return;
}
let promise;
// if no callback, return promise
if (typeof callback !== 'function' && window.Promise) {
promise = new window.Promise((resolve, reject) => {
callback = function(valid) {
resolve(valid);
};
});
}
let valid = true;
let count = 0;
// 如果需要验证的fields为空,调用验证时立刻返回callback
if (this.fields.length === 0 && callback) {
callback(true);
......@@ -90,13 +102,14 @@
if (errors) {
valid = false;
}
if (typeof callback === 'function' && ++count === this.fields.length) {
callback(valid);
}
});
});
if (typeof callback === 'function') {
callback(valid);
} else if (window.Promise) {
return Promise[valid ? 'resolve' : 'reject'](valid); // eslint-disable-line
if (promise) {
return promise;
}
},
validateField(prop, cb) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment