[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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -81,7 +81,7 @@ Filed support all native properties of input tagsuch as `maxlength`、`placeh
| Attribute | Description | Type | Default | Accepted Values |
|-----------|-----------|-----------|-------------|-------------|
| type | Filed type | `String` | `text` | `number` `email` <br> `textarea` `tel` <br> `datetime` `date` <br> `password` `url` |
| type | Filed type | `String` | `text` | `number` `email` `textarea` `tel` `datetime` `date` `password` `url` |
| value | Filed value | `String` | - | - |
| label | Filed label | `String` | - | - |
| disabled | Disable field | `Boolean` | `false` | - |

View File

@ -83,7 +83,7 @@ Filed 默认支持 Input 标签所有的原生属性,比如 `maxlength`、`pla
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|-----------|-----------|-----------|-------------|-------------|
| type | 输入框类型 | `String` | `text` | `number` `email` <br> `textarea` `tel` <br> `datetime` `date` <br> `password` `url` |
| type | 输入框类型 | `String` | `text` | `number` `email` `textarea` `tel` `datetime` `date` `password` `url` |
| value | 输入框的值 | `String` | - | - |
| label | 输入框标签 | `String` | - | - |
| disabled | 是否禁用输入框 | `Boolean` | `false` | - |

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';