diff --git a/examples/docs/en-US/form.md b/examples/docs/en-US/form.md index 1d62ae939..6892678b6 100644 --- a/examples/docs/en-US/form.md +++ b/examples/docs/en-US/form.md @@ -849,8 +849,8 @@ All components in a Form inherit their `size` attribute from that Form. Similarl | Method | Description | Parameters | | ---- | ---- | ---- | -| validate | the method to validate the whole form. Returns a promise if callback is omitted | Function(callback: Function(boolean)) | -| validateField | the method to validate a certain form item | Function(prop: string, callback: Function(errorMessage: string)) | +| validate | validate the whole form. Takes a callback as a param. After validation, the callback will be executed with two params: a boolean indicating if the validation has passed, and an object containing all fields that fail the validation. Returns a promise if callback is omitted | Function(callback: Function(boolean, object)) | +| validateField | validate a certain form item | Function(prop: string, callback: Function(errorMessage: string)) | | resetFields | reset all the fields and remove validation result | — | | clearValidate | clear validation message for all fields | - diff --git a/examples/docs/es/form.md b/examples/docs/es/form.md index 76decfcad..6aaefdee5 100644 --- a/examples/docs/es/form.md +++ b/examples/docs/es/form.md @@ -854,7 +854,7 @@ Todos los componentes de un formulario heredan su atributo `size`. De manera sim | Metodo | Descripción | Parametros | | ------------- | ---------------------------------------- | ---------------------------------------- | -| validate | el método para validar todo el formulario. Devuelve una promesa si se omite el return | Function(callback: Function(boolean)) | +| validate | el método para validar todo el formulario. Takes a callback as a param. After validation, the callback will be executed with two params: a boolean indicating if the validation has passed, and an object containing all fields that fail the validation. Devuelve una promesa si se omite el return | Function(callback: Function(boolean, object)) | | validateField | el método para validar un determinado form item | Function(prop: string, callback: Function(errorMessage: string)) | | resetFields | restablece todos los campos y elimina el resultado de validación | — | | clearValidate | limpia mensaje de validación para todos los campos | - diff --git a/examples/docs/zh-CN/form.md b/examples/docs/zh-CN/form.md index a3077ac78..766bb1c64 100644 --- a/examples/docs/zh-CN/form.md +++ b/examples/docs/zh-CN/form.md @@ -837,7 +837,7 @@ W3C 标准中有如下[规定](https://www.w3.org/MarkUp/html-spec/html-spec_8.h | 方法名 | 说明 | 参数 |---------- |-------------- | -------------- -| validate | 对整个表单进行校验的方法。若不传入回调函数,则会返回一个 promise | Function(callback: Function(boolean)) +| validate | 对整个表单进行校验的方法,参数为一个回调函数。该回调函数会在校验结束后被调用,并传入两个参数:是否校验成功和未通过校验的字段。若不传入回调函数,则会返回一个 promise | Function(callback: Function(boolean, object)) | validateField | 对部分表单字段进行校验的方法 | Function(prop: string, callback: Function(errorMessage: string)) | resetFields | 对整个表单进行重置,将所有字段值重置为初始值并移除校验结果 | - | clearValidate | 移除整个表单的校验结果 | - diff --git a/packages/form/src/form-item.vue b/packages/form/src/form-item.vue index 4981724b7..e1ec4fd6d 100644 --- a/packages/form/src/form-item.vue +++ b/packages/form/src/form-item.vue @@ -192,11 +192,11 @@ model[this.prop] = this.fieldValue; - validator.validate(model, { firstFields: true }, (errors, fields) => { + validator.validate(model, { firstFields: true }, (errors, invalidFields) => { this.validateState = !errors ? 'success' : 'error'; this.validateMessage = errors ? errors[0].message : ''; - callback(this.validateMessage); + callback(this.validateMessage, invalidFields); }); }, clearValidate() { diff --git a/packages/form/src/form.vue b/packages/form/src/form.vue index 2c3a5e1cd..b0bcc5313 100644 --- a/packages/form/src/form.vue +++ b/packages/form/src/form.vue @@ -7,6 +7,8 @@