我如何验证 Element UI 中的 MIXED INPUT
How I can to validate MIXED INPUT in Element UI
我有一个例子https://jsfiddle.net/vintkor/b35kxu90/19/
如何一起验证 input5 和 select 字段?
我在官方文档中没有找到这个
HTML
<el-form ref="form" :model="form" :rules="rules">
<el-form-item prop="input5">
<el-input class="inline-input" placeholder="Please input" v-model="form.input5" style="width: 300px;">
<el-select required v-model="form.select" slot="prepend" placeholder="Select">
<el-option label="Restaurant" value="1"></el-option>
<el-option label="Order No." value="2"></el-option>
<el-option label="Tel" value="3"></el-option>
</el-select>
<el-button slot="append" icon="search" @click=submitForm('form')></el-button>
</el-input>
</el-form-item>
</el-form>
您必须编写自己的自定义验证:
data() {
var validateInput5 = (rule, value, callback) => {
if (value === '') {
callback(new Error('Please enter an input'));
} else if (value !== this.form.select) {
callback(new Error('Please select something'));
} else {
callback();
}
};
return {
form: {
input5: '',
select: '',
},
rules: {
input5: [
{ validator: validateInput5, trigger: 'blur' }
],
}
}
},
我有一个例子https://jsfiddle.net/vintkor/b35kxu90/19/ 如何一起验证 input5 和 select 字段? 我在官方文档中没有找到这个
HTML
<el-form ref="form" :model="form" :rules="rules">
<el-form-item prop="input5">
<el-input class="inline-input" placeholder="Please input" v-model="form.input5" style="width: 300px;">
<el-select required v-model="form.select" slot="prepend" placeholder="Select">
<el-option label="Restaurant" value="1"></el-option>
<el-option label="Order No." value="2"></el-option>
<el-option label="Tel" value="3"></el-option>
</el-select>
<el-button slot="append" icon="search" @click=submitForm('form')></el-button>
</el-input>
</el-form-item>
</el-form>
您必须编写自己的自定义验证:
data() {
var validateInput5 = (rule, value, callback) => {
if (value === '') {
callback(new Error('Please enter an input'));
} else if (value !== this.form.select) {
callback(new Error('Please select something'));
} else {
callback();
}
};
return {
form: {
input5: '',
select: '',
},
rules: {
input5: [
{ validator: validateInput5, trigger: 'blur' }
],
}
}
},