[bugfix] Filed number type value filter (#386)

This commit is contained in:
neverland
2017-12-06 18:06:57 +08:00
committed by GitHub
parent c18b560b0d
commit c2dddeb552
3 changed files with 14 additions and 2 deletions

View File

@@ -29,6 +29,7 @@
class="van-field__control"
:type="type"
:value="value"
@keypress="onKeypress"
@input="onInput"
@focus="$emit('focus')"
@blur="$emit('blur')"
@@ -111,6 +112,17 @@ export default {
this.onIconClick();
},
onKeypress(event) {
if (this.type === 'number') {
const { keyCode } = event;
const allowPoint = this.value.indexOf('.') === -1;
const isValidKey = (keyCode >= 48 && keyCode <= 57) || (keyCode === 46 && allowPoint);
if (!isValidKey) {
event.preventDefault();
}
}
},
adjustSize() {
const el = this.$refs.textarea;
el.style.height = 'auto';