Skip to content

Commit 15d567e

Browse files
committedSep 11, 2015
fix vuejs#1299, correct the loop counter
1 parent 318e77b commit 15d567e

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed
 

‎src/directives/model/select.js

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function initOptions (expression) {
103103
parentNode.removeChild(option)
104104
} else {
105105
el.removeChild(parentNode)
106+
i = el.options.length
106107
}
107108
}
108109
}

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

+29-2
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,10 @@ if (_.inBrowser) {
373373
_.nextTick(function () {
374374
expect(el.firstChild.innerHTML).toBe(
375375
'<optgroup label="X">' +
376-
'<option value="x">x</option><option value="y">y</option>' +
376+
'<option value="x">x</option><option value="y">y</option>' +
377377
'</optgroup>' +
378378
'<optgroup label="Y">' +
379-
'<option value="z">z</option>' +
379+
'<option value="z">z</option>' +
380380
'</optgroup>'
381381
)
382382
var opts = el.firstChild.options
@@ -387,6 +387,33 @@ if (_.inBrowser) {
387387
})
388388
})
389389

390+
it('select + options + optgroup + default option', function (done) {
391+
var vm = new Vue({
392+
el: el,
393+
data: {
394+
test: '',
395+
opts: [
396+
{ label: 'A', options: ['a', 'b'] },
397+
{ label: 'B', options: ['c'] }
398+
]
399+
},
400+
template: '<select v-model="test" options="opts"><option value=""></option></select>'
401+
})
402+
var opts = el.firstChild.options
403+
expect(opts[0].selected).toBe(true)
404+
expect(el.firstChild.value).toBe('')
405+
vm.opts = [
406+
{ label: 'X', options: ['x', 'y'] },
407+
{ label: 'Y', options: ['z'] }
408+
]
409+
_.nextTick(function () {
410+
var opts = el.firstChild.options
411+
expect(opts[0].selected).toBe(true)
412+
expect(el.firstChild.value).toBe('')
413+
done()
414+
})
415+
})
416+
390417
it('select + options with Object value', function (done) {
391418
var vm = new Vue({
392419
el: el,

0 commit comments

Comments
 (0)
Please sign in to comment.