소스 검색

Fix multiple attr in select with undefined value (#4859)

Fix #4855
Eduardo San Martin Morote 9 년 전
부모
커밋
ec7fca8495
2개의 변경된 파일18개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      src/platforms/web/runtime/node-ops.js
  2. 16 0
      test/unit/features/directives/model-select.spec.js

+ 2 - 1
src/platforms/web/runtime/node-ops.js

@@ -7,7 +7,8 @@ export function createElement (tagName: string, vnode: VNode): Element {
   if (tagName !== 'select') {
   if (tagName !== 'select') {
     return elm
     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')
     elm.setAttribute('multiple', 'multiple')
   }
   }
   return elm
   return elm

+ 16 - 0
test/unit/features/directives/model-select.spec.js

@@ -287,6 +287,22 @@ describe('Directive v-model select', () => {
     }).then(done)
     }).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', () => {
   it('multiple with static template', () => {
     const vm = new Vue({
     const vm = new Vue({
       template:
       template: