Skip to content

Commit 8a351e7

Browse files
committed
Merge pull request #861 from holic/disabled-options
Support `disabled` attribute on select options
2 parents e215eeb + 008a1ec commit 8a351e7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/directives/model/select.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ function buildOptions (parent, options) {
107107
} else {
108108
el.text = op.text
109109
el.value = op.value
110+
if (op.disabled) {
111+
el.disabled = true
112+
}
110113
}
111114
} else {
112115
el = document.createElement('optgroup')

test/unit/specs/directives/model_spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,23 @@ if (_.inBrowser) {
245245
data: {
246246
test: 'b',
247247
opts: [
248+
{ text: 'Select an option', value: null, disabled: true },
248249
{ text: 'A', value: 'a' },
249250
{ text: 'B', value: 'b' }
250251
]
251252
},
252253
template: '<select v-model="test" options="opts"></select>'
253254
})
254255
expect(el.firstChild.innerHTML).toBe(
256+
'<option disabled="">Select an option</option>' +
255257
'<option value="a">A</option>' +
256258
'<option value="b">B</option>'
257259
)
258260
var opts = el.firstChild.options
261+
expect(opts[0].disabled).toBe(true)
259262
expect(opts[0].selected).toBe(false)
260-
expect(opts[1].selected).toBe(true)
263+
expect(opts[1].selected).toBe(false)
264+
expect(opts[2].selected).toBe(true)
261265
})
262266

263267
it('select + options + optgroup', function () {

0 commit comments

Comments
 (0)