diff --git a/src/form/README.md b/src/form/README.md index 44b7fdb35..9dbb62bd9 100644 --- a/src/form/README.md +++ b/src/form/README.md @@ -420,9 +420,8 @@ Use [ref](https://vuejs.org/v2/api/#ref) to get Form instance and call instance | Name | Description | Attribute | Return value | |------|------|------|------| -| validate | Validate all fields | - | *Promise* | -| validateField | Validate a filed | *name: string* | *Promise* | -| resetValidation | Reset all validation | - | - | +| validate | Validate form | *name?: string* | *Promise* | +| resetValidation | Reset validation | *name?: string* | - | ### Slots diff --git a/src/form/README.zh-CN.md b/src/form/README.zh-CN.md index 2ae20913b..df58b5d56 100644 --- a/src/form/README.zh-CN.md +++ b/src/form/README.zh-CN.md @@ -452,9 +452,8 @@ export default { | 方法名 | 说明 | 参数 | 返回值 | |------|------|------|------| -| validate | 验证所有表单项,返回 Promise,验证不通过时 reject | - | *Promise* | -| validateField | 验证单个表单项,返回 Promise,验证不通过时 reject | *name: string* | *Promise* | -| resetValidation | 重置所有表单验证提示 | - | - | +| validate | 验证表单,支持传入`name`来验证单个表单项 | *name?: string* | *Promise* | +| resetValidation | 重置表单项的验证提示,支持传入`name`来重置单个表单项 | *name?: string* | - | ### Slots diff --git a/src/form/index.js b/src/form/index.js index c54960e16..d92111b8f 100644 --- a/src/form/index.js +++ b/src/form/index.js @@ -63,11 +63,13 @@ export default createComponent({ }, // @exposed-api - validate() { + validate(name) { + if (name) { + return this.validateField(name); + } return this.validateFirst ? this.validateSeq() : this.validateAll(); }, - // @exposed-api validateField(name) { const matched = this.fields.filter(item => item.name === name); @@ -87,9 +89,11 @@ export default createComponent({ }, // @exposed-api - resetValidation() { + resetValidation(name) { this.fields.forEach(item => { - item.resetValidation(); + if (!name || item.name === name) { + item.resetValidation(); + } }); },