Skip to content

Commit

Permalink
Fix multiple attr in select with undefined value (#4859)
Browse files Browse the repository at this point in the history
Fix #4855
  • Loading branch information
posva authored and yyx990803 committed Feb 6, 2017
1 parent 8bf5af8 commit ec7fca8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/platforms/web/runtime/node-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export function createElement (tagName: string, vnode: VNode): Element {
if (tagName !== 'select') {
return elm
}
if (vnode.data && vnode.data.attrs && 'multiple' in vnode.data.attrs) {
// false or null will remove the attribute but undefined will not
if (vnode.data && vnode.data.attrs && vnode.data.attrs.multiple !== undefined) {
elm.setAttribute('multiple', 'multiple')
}
return elm
Expand Down
16 changes: 16 additions & 0 deletions test/unit/features/directives/model-select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,22 @@ describe('Directive v-model select', () => {
}).then(done)
})

it('should not have multiple attr with falsy values except \'\'', () => {
const vm = new Vue({
template:
'<div>' +
'<select id="undefined" :multiple="undefined"></select>' +
'<select id="null" :multiple="null"></select>' +
'<select id="false" :multiple="false"></select>' +
'<select id="string" :multiple="\'\'"></select>' +
'</div>'
}).$mount()
expect(vm.$el.querySelector('#undefined').multiple).toEqual(false)
expect(vm.$el.querySelector('#null').multiple).toEqual(false)
expect(vm.$el.querySelector('#false').multiple).toEqual(false)
expect(vm.$el.querySelector('#string').multiple).toEqual(true)
})

it('multiple with static template', () => {
const vm = new Vue({
template:
Expand Down

0 comments on commit ec7fca8

Please sign in to comment.