Skip to content

Commit 25fb48d

Browse files
committed
revert v-model behavior without filters (address vuejs#554, vuejs#587)
1 parent 944c794 commit 25fb48d

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

src/directives/model/default.js

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,36 @@ module.exports = {
4747
// if the directive has filters, we need to
4848
// record cursor position and restore it after updating
4949
// the input with the filtered value.
50-
this.listener = function textInputListener () {
51-
if (cpLocked) return
52-
var charsOffset
53-
// some HTML5 input types throw error here
54-
try {
55-
// record how many chars from the end of input
56-
// the cursor was at
57-
charsOffset = el.value.length - el.selectionStart
58-
} catch (e) {}
59-
set()
60-
// force a value update, because in
61-
// certain cases the write filters output the same
62-
// result for different input values, and the Observer
63-
// set events won't be triggered.
64-
_.nextTick(function () {
65-
var newVal = self._watcher.value
66-
self.update(newVal)
67-
if (charsOffset != null) {
68-
var cursorPos =
69-
_.toString(newVal).length - charsOffset
70-
el.setSelectionRange(cursorPos, cursorPos)
50+
this.listener = this.filters
51+
? function textInputListener () {
52+
if (cpLocked) return
53+
var charsOffset
54+
// some HTML5 input types throw error here
55+
try {
56+
// record how many chars from the end of input
57+
// the cursor was at
58+
charsOffset = el.value.length - el.selectionStart
59+
} catch (e) {}
60+
set()
61+
_.nextTick(function () {
62+
// force a value update, because in
63+
// certain cases the write filters output the
64+
// same result for different input values, and
65+
// the Observer set events won't be triggered.
66+
var newVal = self._watcher.value
67+
self.update(newVal)
68+
if (charsOffset != null) {
69+
var cursorPos =
70+
_.toString(newVal).length - charsOffset
71+
el.setSelectionRange(cursorPos, cursorPos)
72+
}
73+
})
7174
}
72-
})
73-
}
75+
: function textInputListener () {
76+
if (cpLocked) return
77+
set()
78+
}
79+
7480
this.event = lazy ? 'change' : 'input'
7581
_.on(el, this.event, this.listener)
7682

0 commit comments

Comments
 (0)