Browse Source

Merge pull request #861 from holic/disabled-options

Support `disabled` attribute on select options
Evan You 11 years ago
parent
commit
8a351e7568
2 changed files with 8 additions and 1 deletions
  1. 3 0
      src/directives/model/select.js
  2. 5 1
      test/unit/specs/directives/model_spec.js

+ 3 - 0
src/directives/model/select.js

@@ -107,6 +107,9 @@ function buildOptions (parent, options) {
       } else {
         el.text = op.text
         el.value = op.value
+        if (op.disabled) {
+          el.disabled = true
+        }
       }
     } else {
       el = document.createElement('optgroup')

+ 5 - 1
test/unit/specs/directives/model_spec.js

@@ -245,6 +245,7 @@ if (_.inBrowser) {
         data: {
           test: 'b',
           opts: [
+            { text: 'Select an option', value: null, disabled: true },
             { text: 'A', value: 'a' },
             { text: 'B', value: 'b' }
           ]
@@ -252,12 +253,15 @@ if (_.inBrowser) {
         template: '<select v-model="test" options="opts"></select>'
       })
       expect(el.firstChild.innerHTML).toBe(
+        '<option disabled="">Select an option</option>' +
         '<option value="a">A</option>' +
         '<option value="b">B</option>'
       )
       var opts = el.firstChild.options
+      expect(opts[0].disabled).toBe(true)
       expect(opts[0].selected).toBe(false)
-      expect(opts[1].selected).toBe(true)
+      expect(opts[1].selected).toBe(false)
+      expect(opts[2].selected).toBe(true)
     })
 
     it('select + options + optgroup', function () {