8000 force v-model sync on change instead of blur (fix #2400) · ctyu/vue@df01719 · GitHub
[go: up one dir, main page]

Skip to content

Commit df01719

Browse files
committed
force v-model sync on change instead of blur (fix vuejs#2400)
1 parent 59868bb commit df01719

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/directives/public/model/text.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ export default {
5353
})
5454
this.on('blur', function () {
5555
self.focused = false
56-
// do not sync value after fragment removal (#2017)
57-
if (!self._frag || self._frag.inserted) {
58-
self.rawListener()
59-
}
6056
})
6157
}
6258

@@ -96,12 +92,12 @@ export default {
9692
this.hasjQuery = typeof jQuery === 'function'
9793
if (this.hasjQuery) {
9894
const method = jQuery.fn.on ? 'on' : 'bind'
99-
jQuery(el)[method]('change', this.listener)
95+
jQuery(el)[method]('change', this.rawListener)
10096
if (!lazy) {
10197
jQuery(el)[method]('input', this.listener)
10298
}
10399
} else {
104-
this.on('change', this.listener)
100+
this.on('change', this.rawListener)
105101
if (!lazy) {
106102
this.on('input', this.listener)
107103
}

test/unit/specs/directives/public/model_spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ describe('v-model', function () {
499499
_.nextTick(function () {
500500
expect(el.firstChild.value).toBe('cc')
501501
expect(vm.test).toBe('cc')
502+
trigger(el.firstChild, 'change')
502503
trigger(el.firstChild, 'blur')
503504
_.nextTick(function () {
504505
expect(el.firstChild.value).toBe('CC')
@@ -529,6 +530,7 @@ describe('v-model', function () {
529530
_.nextTick(function () {
530531
expect(el.firstChild.value).toBe('cc')
531532
expect(vm.test).toBe('CC')
533+
trigger(el.firstChild, 'change')
532534
trigger(el.firstChild, 'blur')
533535
_.nextTick(function () {
534536
expect(el.firstChild.value).toBe('CC')
@@ -712,7 +714,8 @@ describe('v-model', function () {
712714
expect(vm.test).toBe('d')
713715
setTimeout(function () {
714716
el.firstChild.value = 'e'
715-
// blur should trigger change instantly without debounce
717+
// change should trigger change instantly without debounce
718+
trigger(el.firstChild, 'change')
716719
trigger(el.firstChild, 'blur')
717720
_.nextTick(function () {
718721
expect(spy.calls.count()).toBe(2)

0 commit comments

Comments
 (0)
0