Skip to content

Commit

Permalink
x-input: catch input exception when type = number #2960 (#3084)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Millent authored and airyland committed Apr 10, 2019
1 parent 6db4465 commit 545f1f9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/x-input/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ export default {
}
},
currentValue (newVal, oldVal) {
let selection = null
if (!this.equalWith && newVal) {
this.validateEqual()
}
Expand All @@ -548,11 +549,13 @@ export default {
} else {
this.validate()
}
let selection = this.$refs.input.selectionStart
let direction = newVal.length - oldVal.length
selection = this._getInputMaskSelection(selection, direction, this.maskValue(newVal))
this.lastDirection = direction
// #2960
try {
selection = this.$refs.input.selectionStart
let direction = newVal.length - oldVal.length
selection = this._getInputMaskSelection(selection, direction, this.maskValue(newVal))
this.lastDirection = direction
} catch (e) {}
this.$emit('input', this.maskValue(newVal))
// #2810
this.$nextTick(() => {
Expand Down
1 change: 1 addition & 0 deletions src/demo_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"Issue624#/issue/624",
"Issue649#/issue/649",
"Issue865#/issue/865",
"Issue2960#/issue/2960",
"Swipeout",
"TabbarSimple",
"Device#/plugin/device",
Expand Down
37 changes: 37 additions & 0 deletions src/demos/Issue2960.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<div>
<group title="check if value is valid when required===false">
<x-input type="number" v-model="currentValue"></x-input>
<h1>{{currentValue}}</h1>
</group>
<!--
目前唯一允许安全选择文本的元素是:
<input type="text|search|password|tel|url">如下所述:
https://stackoverflow.com/questions/21177489/selectionstart-selectionend-on-input-type-number-no-longer-allowed-in-chrome
-->
</div>
</template>

<script>
import { XInput, Group, XButton, Cell } from 'vux'
export default {
components: {
XInput,
XButton,
Group,
Cell
},
name: 'Issue2960',
data () {
return {
currentValue: 0
}
}
}
</script>

<style scoped>
</style>

1 comment on commit 545f1f9

@kevin611003
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will it be released to npm?

Please sign in to comment.