From 96a9d5fbce64ba02cfe6bc5ec3ee284cf775d830 Mon Sep 17 00:00:00 2001 From: Justin Schroeder Date: Mon, 1 Mar 2021 20:05:11 -0500 Subject: [PATCH] Adds #366 allowing easy disabling for select options --- src/inputs/FormulateInputSelect.vue | 6 ++++-- test/unit/FormulateInputSelect.test.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/inputs/FormulateInputSelect.vue b/src/inputs/FormulateInputSelect.vue index b7b7a15..4b74639 100644 --- a/src/inputs/FormulateInputSelect.vue +++ b/src/inputs/FormulateInputSelect.vue @@ -37,7 +37,8 @@ v-for="option in options" :key="option.id" :value="option.value" - v-bind="option.attributes || {}" + :disabled="!!option.disabled" + v-bind="option.attributes || option.attrs || {}" v-text="option.label" /> @@ -53,7 +54,8 @@ v-for="option in subOptions" :key="option.id" :value="option.value" - v-bind="option.attributes || {}" + :disabled="!!option.disabled" + v-bind="option.attributes || option.attrs || {}" v-text="option.label" /> diff --git a/test/unit/FormulateInputSelect.test.js b/test/unit/FormulateInputSelect.test.js index b1afcbf..771f2bd 100644 --- a/test/unit/FormulateInputSelect.test.js +++ b/test/unit/FormulateInputSelect.test.js @@ -48,6 +48,16 @@ describe('FormulateInputSelect', () => { expect(wrapper.find('select[name="foo"]').exists()).toBe(true) }) + it('Allows disabling options', () => { + const wrapper = mount(FormulateInput, { propsData: { type: 'select', options: [ + { label: 'a', value: 'a'}, + { label: 'b', value: 'b', disabled: true }, + { label: 'c', value: 'c'} + ], name: 'foo' } }) + expect(wrapper.find('option[value="a"]').attributes('disabled')).toBe(undefined) + expect(wrapper.find('option[value="b"]').attributes('disabled')).toBe('disabled') + }) + it('additional context does not bleed through to text select attributes', () => { const wrapper = mount(FormulateInput, { propsData: { type: 'select' } } ) expect(Object.keys(wrapper.find('select').attributes())).toEqual(["id"])