Skip to content

Commit 96a9d5f

Browse files
Adds #366 allowing easy disabling for select options
1 parent 39298d7 commit 96a9d5f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/inputs/FormulateInputSelect.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
v-for="option in options"
3838
:key="option.id"
3939
:value="option.value"
40-
v-bind="option.attributes || {}"
40+
:disabled="!!option.disabled"
41+
v-bind="option.attributes || option.attrs || {}"
4142
v-text="option.label"
4243
/>
4344
</template>
@@ -53,7 +54,8 @@
5354
v-for="option in subOptions"
5455
:key="option.id"
5556
:value="option.value"
56-
v-bind="option.attributes || {}"
57+
:disabled="!!option.disabled"
58+
v-bind="option.attributes || option.attrs || {}"
5759
v-text="option.label"
5860
/>
5961
</optgroup>

test/unit/FormulateInputSelect.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ describe('FormulateInputSelect', () => {
4848
expect(wrapper.find('select[name="foo"]').exists()).toBe(true)
4949
})
5050

51+
it('Allows disabling options', () => {
52+
const wrapper = mount(FormulateInput, { propsData: { type: 'select', options: [
53+
{ label: 'a', value: 'a'},
54+
{ label: 'b', value: 'b', disabled: true },
55+
{ label: 'c', value: 'c'}
56+
], name: 'foo' } })
57+
expect(wrapper.find('option[value="a"]').attributes('disabled')).toBe(undefined)
58+
expect(wrapper.find('option[value="b"]').attributes('disabled')).toBe('disabled')
59+
})
60+
5161
it('additional context does not bleed through to text select attributes', () => {
5262
const wrapper = mount(FormulateInput, { propsData: { type: 'select' } } )
5363
expect(Object.keys(wrapper.find('select').attributes())).toEqual(["id"])

0 commit comments

Comments
 (0)