Skip to content

Commit 8bb1e58

Browse files
defccyyx990803
authored andcommittedOct 11, 2016
fix multiple select render (#3908)
* fix multiple select render. The mutliple attribute of select dosen't apply at first, so the mutli selected option dosen't work when patching * keep the vnode.data the same as before
1 parent 71ef9d6 commit 8bb1e58

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed
 

‎src/core/vdom/patch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export function createPatchFunction (backend) {
115115
}
116116
vnode.elm = vnode.ns
117117
? nodeOps.createElementNS(vnode.ns, tag)
118-
: nodeOps.createElement(tag)
118+
: nodeOps.createElement(tag, vnode)
119119
setScope(vnode)
120120
createChildren(vnode, children, insertedVnodeQueue)
121121
if (isDef(data)) {

‎src/platforms/web/runtime/node-ops.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22

33
import { namespaceMap } from 'web/util/index'
44

5-
export function createElement (tagName: string): Element {
6-
return document.createElement(tagName)
5+
export function createElement (tagName: string, vnode: VNode): Element {
6+
const elm = document.createElement(tagName)
7+
if (tagName !== 'select') {
8+
return elm
9+
}
10+
if (vnode.data && vnode.data.attrs && 'multiple' in vnode.data.attrs) {
11+
elm.setAttribute('multiple', 'multiple')
12+
}
13+
return elm
714
}
815

916
export function createElementNS (namespace: string, tagName: string): Element {

‎test/unit/features/directives/model-select.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@ describe('Directive v-model select', () => {
189189
}).then(done)
190190
})
191191

192+
it('multiple with static template', () => {
193+
const vm = new Vue({
194+
template:
195+
'<select multiple>' +
196+
'<option selected>a</option>' +
197+
'<option selected>b</option>' +
198+
'<option selected>c</option>' +
199+
'</select>'
200+
}).$mount()
201+
var opts = vm.$el.options
202+
expect(opts[0].selected).toBe(true)
203+
expect(opts[1].selected).toBe(true)
204+
expect(opts[2].selected).toBe(true)
205+
})
206+
192207
it('multiple + v-for', done => {
193208
const vm = new Vue({
194209
data: {

0 commit comments

Comments
 (0)
Please sign in to comment.