mirror of https://github.com/ElemeFE/element
Docs: add form immediate example
parent
e5898f28ad
commit
7f35cee960
|
@ -585,6 +585,74 @@ All components in a Form inherit their `size` attribute from that Form. Similarl
|
||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
### Return form validation result immediately
|
||||||
|
|
||||||
|
:::demo Execute `callback` immediately when the validation of the first form item fails
|
||||||
|
```html
|
||||||
|
<el-form :model="immedidateForm" ref="immedidateForm" immediateValid>
|
||||||
|
<el-form-item
|
||||||
|
label="Name"
|
||||||
|
prop="name"
|
||||||
|
:rules="[
|
||||||
|
{ required: true, message: 'Name is not empty'},
|
||||||
|
{ validator: asyncValid, trigger: ['blur']}
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<el-input v-model="immedidateForm.name" autocomplete="off"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
label="Age"
|
||||||
|
prop="age"
|
||||||
|
:rules="[{required: true, message: 'Age is not empty' }]">
|
||||||
|
<el-input v-model="immedidateForm.age" autocomplete="off" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" @click="submitForm('immedidateForm')" :loading="submitting">Submit</el-button>
|
||||||
|
<el-button @click="resetForm('immedidateForm')">Reset</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
submitting: false,
|
||||||
|
immedidateForm: {
|
||||||
|
name: '',
|
||||||
|
age: ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
asyncValid(rule, value, callback) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if(value === "element") {
|
||||||
|
callback("Name cannot be repeated");
|
||||||
|
}else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}, 2000)
|
||||||
|
},
|
||||||
|
submitForm(formName) {
|
||||||
|
this.submitting = true;
|
||||||
|
this.$refs[formName].validate((valid) => {
|
||||||
|
console.log('callback immediate exec!');
|
||||||
|
if (valid) {
|
||||||
|
alert('submit!');
|
||||||
|
} else {
|
||||||
|
console.log('error submit!!');
|
||||||
|
}
|
||||||
|
this.submitting = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
resetForm(formName) {
|
||||||
|
this.$refs[formName].resetFields();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
:::
|
||||||
|
|
||||||
### Form Attributes
|
### Form Attributes
|
||||||
|
|
||||||
| Attribute | Description | Type | Accepted Values | Default |
|
| Attribute | Description | Type | Accepted Values | Default |
|
||||||
|
|
|
@ -599,6 +599,75 @@ Todos los componentes de un formulario heredan su atributo `size`. De manera sim
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
### Return form validation result immediately
|
||||||
|
|
||||||
|
:::demo Execute `callback` immediately when the validation of the first form item fails
|
||||||
|
```html
|
||||||
|
<el-form :model="immedidateForm" ref="immedidateForm" immediateValid>
|
||||||
|
<el-form-item
|
||||||
|
label="Name"
|
||||||
|
prop="name"
|
||||||
|
:rules="[
|
||||||
|
{ required: true, message: 'Name is not empty'},
|
||||||
|
{ validator: asyncValid, trigger: ['blur']}
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<el-input v-model="immedidateForm.name" autocomplete="off"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
label="Age"
|
||||||
|
prop="age"
|
||||||
|
:rules="[{required: true, message: 'Age is not empty' }]">
|
||||||
|
<el-input v-model="immedidateForm.age" autocomplete="off" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" @click="submitForm('immedidateForm')" :loading="submitting">Submit</el-button>
|
||||||
|
<el-button @click="resetForm('immedidateForm')">Reset</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
submitting: false,
|
||||||
|
immedidateForm: {
|
||||||
|
name: '',
|
||||||
|
age: ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
asyncValid(rule, value, callback) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if(value === "element") {
|
||||||
|
callback("Name cannot be repeated");
|
||||||
|
}else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}, 2000)
|
||||||
|
},
|
||||||
|
submitForm(formName) {
|
||||||
|
this.submitting = true;
|
||||||
|
this.$refs[formName].validate((valid) => {
|
||||||
|
console.log('callback immediate exec!');
|
||||||
|
if (valid) {
|
||||||
|
alert('submit!');
|
||||||
|
} else {
|
||||||
|
console.log('error submit!!');
|
||||||
|
}
|
||||||
|
this.submitting = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
resetForm(formName) {
|
||||||
|
this.$refs[formName].resetFields();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
:::
|
||||||
|
|
||||||
|
|
||||||
### Form Atributos
|
### Form Atributos
|
||||||
|
|
||||||
| Atributo | Descripción | Tipo | Valores aceptados | Por defecto |
|
| Atributo | Descripción | Tipo | Valores aceptados | Por defecto |
|
||||||
|
|
|
@ -584,6 +584,75 @@ Tout les composants d'un formulaire héritent leur attribut `size` de ce formula
|
||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
### Return form validation result immediately
|
||||||
|
|
||||||
|
:::demo Exécuter `callback` immédiatement lorsque la validation du premier élément de formulaire échoue
|
||||||
|
```html
|
||||||
|
<el-form :model="immedidateForm" ref="immedidateForm" immediateValid>
|
||||||
|
<el-form-item
|
||||||
|
label="Name"
|
||||||
|
prop="name"
|
||||||
|
:rules="[
|
||||||
|
{ required: true, message: 'Le nom n'est pas vide'},
|
||||||
|
{ validator: asyncValid, trigger: ['blur']}
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<el-input v-model="immedidateForm.name" autocomplete="off"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
label="Age"
|
||||||
|
prop="age"
|
||||||
|
:rules="[{required: true, message: 'L'âge n'est pas vide' }]">
|
||||||
|
<el-input v-model="immedidateForm.age" autocomplete="off" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" @click="submitForm('immedidateForm')" :loading="submitting">Submit</el-button>
|
||||||
|
<el-button @click="resetForm('immedidateForm')">Reset</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
submitting: false,
|
||||||
|
immedidateForm: {
|
||||||
|
name: '',
|
||||||
|
age: ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
asyncValid(rule, value, callback) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if(value === "element") {
|
||||||
|
callback("Le nom ne peut pas être répété");
|
||||||
|
}else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}, 2000)
|
||||||
|
},
|
||||||
|
submitForm(formName) {
|
||||||
|
this.submitting = true;
|
||||||
|
this.$refs[formName].validate((valid) => {
|
||||||
|
console.log('callback immediate exec!');
|
||||||
|
if (valid) {
|
||||||
|
alert('submit!');
|
||||||
|
} else {
|
||||||
|
console.log('error submit!!');
|
||||||
|
}
|
||||||
|
this.submitting = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
resetForm(formName) {
|
||||||
|
this.$refs[formName].resetFields();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
:::
|
||||||
|
|
||||||
|
|
||||||
### Attributs de Form
|
### Attributs de Form
|
||||||
|
|
||||||
| Attribut | Description | Type | Valeurs acceptées | Défaut |
|
| Attribut | Description | Type | Valeurs acceptées | Défaut |
|
||||||
|
|
|
@ -630,7 +630,7 @@ W3C 标准中有如下[规定](https://www.w3.org/MarkUp/html-spec/html-spec_8.h
|
||||||
submitForm(formName) {
|
submitForm(formName) {
|
||||||
this.submitting = true;
|
this.submitting = true;
|
||||||
this.$refs[formName].validate((valid) => {
|
this.$refs[formName].validate((valid) => {
|
||||||
console.log('immediate callback exec!');
|
console.log('callback immediate exec!');
|
||||||
if (valid) {
|
if (valid) {
|
||||||
alert('submit!');
|
alert('submit!');
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue