1.4.6
MacOS Sierra 10.12.6 chrome 61
2.5.2
https://jsfiddle.net/0omh3aca/1/
<script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/[email protected]/lib/index.js"></script>
<div id="app">
<el-form :model="numberValidateForm" ref="numberValidateForm" label-width="100px" class="demo-ruleForm">
<el-form-item label="age" prop="age" :rules="[
{ required: true, message: 'age is required', trigger: 'blur'},
{ type: 'number', message: 'age must be a number'}
]">
<el-input type="age" v-model.number="numberValidateForm.age" auto-complete="off"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('numberValidateForm')">Submit</el-button>
<el-button @click="resetForm('numberValidateForm')">Reset</el-button>
</el-form-item>
</el-form>
</div>
var Main = {
data() {
return {
numberValidateForm: {
age: ''
}
};
},
methods: {
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
alert('submit!');
} else {
console.log('error submit!!');
return false;
}
});
},
resetForm(formName) {
this.$refs[formName].resetFields();
}
}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
No error msg is shown.
The error msg of first rule is shown: 'age is required'.
Anyway, this is very weird.
Actually in async-validator, type is always tested against the value even if you don't declare it explicitly. Besides, type defaults to 'string', so a number will always fail it.
To avoid this behavior, you may need to add a pattern to the first rule: https://jsfiddle.net/0omh3aca/2/
Most helpful comment
Actually in
async-validator,typeis always tested against the value even if you don't declare it explicitly. Besides,typedefaults to'string', so a number will always fail it.To avoid this behavior, you may need to add a
patternto the first rule: https://jsfiddle.net/0omh3aca/2/