mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-10-09 02:09:57 +08:00
[bugfix] Filed number type value filter (#386)
This commit is contained in:
parent
c18b560b0d
commit
c2dddeb552
@ -81,7 +81,7 @@ Filed support all native properties of input tag,such as `maxlength`、`placeh
|
|||||||
|
|
||||||
| Attribute | Description | Type | Default | Accepted Values |
|
| 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` | - | - |
|
| value | Filed value | `String` | - | - |
|
||||||
| label | Filed label | `String` | - | - |
|
| label | Filed label | `String` | - | - |
|
||||||
| disabled | Disable field | `Boolean` | `false` | - |
|
| disabled | Disable field | `Boolean` | `false` | - |
|
||||||
|
@ -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` | - | - |
|
| value | 输入框的值 | `String` | - | - |
|
||||||
| label | 输入框标签 | `String` | - | - |
|
| label | 输入框标签 | `String` | - | - |
|
||||||
| disabled | 是否禁用输入框 | `Boolean` | `false` | - |
|
| disabled | 是否禁用输入框 | `Boolean` | `false` | - |
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
class="van-field__control"
|
class="van-field__control"
|
||||||
:type="type"
|
:type="type"
|
||||||
:value="value"
|
:value="value"
|
||||||
|
@keypress="onKeypress"
|
||||||
@input="onInput"
|
@input="onInput"
|
||||||
@focus="$emit('focus')"
|
@focus="$emit('focus')"
|
||||||
@blur="$emit('blur')"
|
@blur="$emit('blur')"
|
||||||
@ -111,6 +112,17 @@ export default {
|
|||||||
this.onIconClick();
|
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() {
|
adjustSize() {
|
||||||
const el = this.$refs.textarea;
|
const el = this.$refs.textarea;
|
||||||
el.style.height = 'auto';
|
el.style.height = 'auto';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user