File tree Expand file tree Collapse file tree 2 files changed +49
-4
lines changed
test/unit/specs/directives Expand file tree Collapse file tree 2 files changed +49
-4
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,12 @@ module.exports = {
43
43
update : function ( value ) {
44
44
var el = this . el
45
45
el . selectedIndex = - 1
46
+ if ( ! value ) {
47
+ if ( this . defaultOption ) {
48
+ this . defaultOption . selected = true
49
+ }
50
+ return
51
+ }
46
52
var multi = this . multiple && _ . isArray ( value )
47
53
var options = el . options
48
54
var i = options . length
@@ -75,11 +81,22 @@ module.exports = {
75
81
76
82
function initOptions ( expression ) {
77
83
var self = this
84
+ var el = self . el
85
+ var defaultOption = self . defaultOption = self . el . options [ 0 ]
78
86
var descriptor = dirParser . parse ( expression ) [ 0 ]
79
87
function optionUpdateWatcher ( value ) {
80
88
if ( _ . isArray ( value ) ) {
81
- self . el . innerHTML = ''
82
- buildOptions ( self . el , value )
89
+ // clear old options.
90
+ // cannot reset innerHTML here because IE family get
91
+ // confused during compilation.
92
+ var i = el . options . length
93
+ while ( i -- ) {
94
+ var option = el . options [ i ]
95
+ if ( option !== defaultOption ) {
96
+ el . removeChild ( option )
97
+ }
98
+ }
99
+ buildOptions ( el , value )
83
100
self . forceUpdate ( )
84
101
} else {
85
102
process . env . NODE_ENV !== 'production' && _ . warn (
Original file line number Diff line number Diff line change @@ -369,11 +369,39 @@ if (_.inBrowser) {
369
369
template : '<select v-model="test" options="opts | aFilter"></select>'
370
370
} )
371
371
expect ( el . firstChild . innerHTML ) . toBe (
372
- '<option value="a0">a0</option>' +
373
- '<option value="b1">b1</option>'
372
+ '<option value="a0">a0</option>' +
373
+ '<option value="b1">b1</option>'
374
374
)
375
375
} )
376
376
377
+ it ( 'select + options + static option' , function ( done ) {
378
+ var vm = new Vue ( {
379
+ el : el ,
380
+ data : {
381
+ opts : [ 'a' , 'b' ]
382
+ } ,
383
+ template :
384
+ '<select v-model="test" options="opts">' +
385
+ '<option value="">default...</option>' +
386
+ '</select>'
387
+ } )
388
+ expect ( el . firstChild . innerHTML ) . toBe (
389
+ '<option value="">default...</option>' +
390
+ '<option value="a">a</option>' +
391
+ '<option value="b">b</option>'
392
+ )
393
+ expect ( el . firstChild . options [ 0 ] . selected ) . toBe ( true )
394
+ vm . opts = [ 'c' ]
395
+ _ . nextTick ( function ( ) {
396
+ expect ( el . firstChild . innerHTML ) . toBe (
397
+ '<option value="">default...</option>' +
398
+ '<option value="c">c</option>'
399
+ )
400
+ expect ( el . firstChild . options [ 0 ] . selected ) . toBe ( true )
401
+ done ( )
402
+ } )
403
+ } )
404
+
377
405
it ( 'text' , function ( done ) {
378
406
var vm = new Vue ( {
379
407
el : el ,
You can’t perform that action at this time.
0 commit comments