mirror of
https://github.com/youzan/vant.git
synced 2025-10-22 20:04:09 +00:00
feat(Form): add validateField method
This commit is contained in:
@@ -67,6 +67,25 @@ export default createComponent({
|
||||
return this.validateFirst ? this.validateSeq() : this.validateAll();
|
||||
},
|
||||
|
||||
// @exposed-api
|
||||
validateField(name) {
|
||||
const matched = this.fields.filter(item => item.name === name);
|
||||
|
||||
if (matched.length) {
|
||||
return new Promise((resolve, reject) => {
|
||||
matched[0].validate().then(error => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.reject();
|
||||
},
|
||||
|
||||
// @exposed-api
|
||||
resetValidation() {
|
||||
this.fields.forEach(item => {
|
||||
|
Reference in New Issue
Block a user