[bugfix] Field: maxlength not work when type = number (#1839)

This commit is contained in:
neverland
2018-09-20 21:15:52 +08:00
committed by GitHub
parent 4c7c2d7b76
commit efa264d612
2 changed files with 37 additions and 1 deletions
+15 -1
View File
@@ -105,6 +105,7 @@ export default create({
},
mounted() {
this.format();
this.$nextTick(this.adjustSize);
},
@@ -129,8 +130,21 @@ export default create({
this.$refs.input && this.$refs.input.blur();
},
// native maxlength not work when type = number
format(target = this.$refs.input) {
let { value } = target;
const { maxlength } = this.$attrs;
if (this.isDef(maxlength) && value.length > maxlength) {
value = value.slice(0, maxlength);
target.value = value;
}
return value;
},
onInput(event) {
this.$emit('input', event.target.value);
this.$emit('input', this.format(event.target));
},
onFocus(event) {