Skip to content

Commit 4e6ad72

Browse files
committed
fix input event handler for Chinese input methods
1 parent d4b09ca commit 4e6ad72

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/directives/model.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ module.exports = {
3838
try {
3939
cursorPos = el.selectionStart
4040
} catch (e) {}
41-
self.vm.$set(self.key, el[attr])
42-
if (cursorPos !== undefined) {
43-
el.setSelectionRange(cursorPos, cursorPos)
44-
}
41+
// `input` event has weird updating issue with
42+
// International (e.g. Chinese) input methods,
43+
// have to use a Timeout to hack around it...
44+
setTimeout(function () {
45+
self.vm.$set(self.key, el[attr])
46+
if (cursorPos !== undefined) {
47+
el.setSelectionRange(cursorPos, cursorPos)
48+
}
49+
}, 0)
4550
}
4651
: function () {
4752
// no filters, don't let it trigger update()

test/functional/specs/validation.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ casper.test.begin('Validation', 4, function (test) {
44
.start('./fixtures/validation.html', function () {
55
test.assertElementCount('.valid', 0)
66
this.sendKeys('input', '@hello.com')
7+
})
8+
.then(function () {
79
test.assertElementCount('.valid', 1)
810

911
this.evaluate(function () {
1012
document.querySelector('input').setSelectionRange(4,4)
1113
})
12-
1314
this.sendKeys('input', 'hoho')
15+
})
16+
.then(function () {
1417
test.assertElementCount('.valid', 1)
1518
test.assertField('email', '[email protected]')
1619
})

test/unit/specs/directives.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ describe('UNIT: Directives', function () {
379379
assert.ok(removed)
380380
})
381381

382-
it('should not lock during vm.$set if it has filters', function () {
382+
it('should not lock during vm.$set if it has filters', function (done) {
383383
var triggered = false
384384
var dir = mockDirective('model', 'input', 'text')
385385
dir.filters = []
@@ -390,7 +390,11 @@ describe('UNIT: Directives', function () {
390390
}}
391391
dir.el.value = 'foo'
392392
dir.el.dispatchEvent(mockHTMLEvent('input'))
393-
assert.ok(triggered)
393+
// timeout becuase the update is async
394+
setTimeout(function () {
395+
assert.ok(triggered)
396+
done()
397+
}, 1)
394398
})
395399

396400
after(function () {

0 commit comments

Comments
 (0)