FormItem: using slot-scope to display validation message (#12715)

* Updated el-form-item to accept custom error message via slot

* FormItem: updated slot name in docs

* updated spanish and chinese translations

* Update form.md

* Update form.md

* Update form.md

* Update form.md
pull/12759/head
Yamen Sharaf 2018-09-13 12:19:44 +02:00 committed by hetech
parent 2d6b5fceed
commit ea27fb8fbf
4 changed files with 31 additions and 12 deletions

View File

@ -879,9 +879,14 @@ All components in a Form inherit their `size` attribute from that Form. Similarl
| — | content of Form Item |
| label | content of label |
### Form-Item Scoped Slot
| Name | Description |
|---------------|-------------|
| error | Custom content to display validation message. The scope parameter is { error } |
### Form-Item Methods
| Method | Description | Parameters |
| ---- | ---- | ---- |
| resetField | reset current field and remove validation result | — |
| clearValidate | remove validation status of the field | -
| clearValidate | remove validation status of the field | - |

View File

@ -884,6 +884,11 @@ Todos los componentes de un formulario heredan su atributo `size`. De manera sim
| — | contenido del Form Item |
| label | contenido de la etiqueta |
### Form-Item Scoped Slot
| Name | Description |
|---------------|-------------|
| error | Custom content to display validation message. The scope parameter is { error } |
### Form-Item Metodo
| Metodo | Descripción | Parametros |

View File

@ -867,6 +867,11 @@ W3C 标准中有如下[规定](https://www.w3.org/MarkUp/html-spec/html-spec_8.h
| — | Form Item 的内容 |
| label | 标签文本的内容 |
### Form-Item Scoped Slot
| name | 说明 |
|--------|--------|
| error | 自定义表单校验信息的显示方式,参数为 { error } |
### Form-Item Methods
| 方法名 | 说明 | 参数

View File

@ -14,17 +14,21 @@
<div class="el-form-item__content" :style="contentStyle">
<slot></slot>
<transition name="el-zoom-in-top">
<div
v-if="validateState === 'error' && showMessage && form.showMessage"
class="el-form-item__error"
:class="{
'el-form-item__error--inline': typeof inlineMessage === 'boolean'
? inlineMessage
: (elForm && elForm.inlineMessage || false)
}"
>
{{validateMessage}}
</div>
<slot
v-if="validateState === 'error' && showMessage && form.showMessage"
name="error"
:error="validateMessage">
<div
class="el-form-item__error"
:class="{
'el-form-item__error--inline': typeof inlineMessage === 'boolean'
? inlineMessage
: (elForm && elForm.inlineMessage || false)
}"
>
{{validateMessage}}
</div>
</slot>
</transition>
</div>
</div>