diff --git a/src/platforms/web/runtime/node-ops.js b/src/platforms/web/runtime/node-ops.js index 8f8c7026932..1516d86bee5 100644 --- a/src/platforms/web/runtime/node-ops.js +++ b/src/platforms/web/runtime/node-ops.js @@ -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 diff --git a/test/unit/features/directives/model-select.spec.js b/test/unit/features/directives/model-select.spec.js index 31b9350db2b..01be1c1d239 100644 --- a/test/unit/features/directives/model-select.spec.js +++ b/test/unit/features/directives/model-select.spec.js @@ -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: + '
' + + '' + + '' + + '' + + '' + + '
' + }).$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: