Browse Source

Form: emits error message on validate event (#12860)

* Form: Emits error message on validate events

* Update form.md
Yamen Sharaf 6 years ago
parent
commit
44a85b8e60

+ 1 - 1
examples/docs/en-US/form.md

@@ -858,7 +858,7 @@ All components in a Form inherit their `size` attribute from that Form. Similarl
 ### Form Events
 | Event Name | Description | Parameters |
 |----------- |------------ |----------- |
-| validate   | triggers after a form item is validated | prop name of the form item being validated, whether validation is passed |
+| validate   | triggers after a form item is validated | prop name of the form item being validated, whether validation is passed and the error message if not |
 
 ### Form-Item Attributes
 

+ 3 - 3
examples/docs/es/form.md

@@ -871,9 +871,9 @@ Todos los componentes de un formulario heredan su atributo `size`. De manera sim
 
 ### Form Events
 
-| Nombre   | Descripción                                          | Parametros                                                                                             |
-| -------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
-| validate | se dispara después de validar un item del formulario | la propiedad (`prop name`) nombre del item del form que se esta validando, si la validacion paso o no. |
+| Nombre   | Descripción                                          | Parametros                                                   |
+| -------- | ---------------------------------------------------- | ------------------------------------------------------------ |
+| validate | se dispara después de validar un item del formulario | la propiedad (`prop name`) nombre del item del form que se esta validando, si la validacion paso o no, mensaje de error si existe. |
 
 ### Form-Item Atributos
 

+ 1 - 1
examples/docs/zh-CN/form.md

@@ -846,7 +846,7 @@ W3C 标准中有如下[规定](https://www.w3.org/MarkUp/html-spec/html-spec_8.h
 ### Form Events
 | 事件名称 | 说明    | 回调参数  |
 |--------- |-------- |---------- |
-| validate | 任一表单项被校验后触发 | 被校验的表单项 prop 值,校验是否通过 |
+| validate | 任一表单项被校验后触发 | 被校验的表单项 prop 值,校验是否通过,错误消息(如果存在) |
 
 ### Form-Item Attributes
 

+ 1 - 1
packages/form/src/form-item.vue

@@ -199,7 +199,7 @@
           this.validateMessage = errors ? errors[0].message : '';
 
           callback(this.validateMessage, invalidFields);
-          this.elForm && this.elForm.$emit('validate', this.prop, !errors);
+          this.elForm && this.elForm.$emit('validate', this.prop, !errors, this.validateMessage || null);
         });
       },
       clearValidate() {