diff --git a/app/assets/javascripts/admin/addon/components/site-settings/compact-list.hbs b/app/assets/javascripts/admin/addon/components/site-settings/compact-list.hbs index bd6989af094..4dda0f48004 100644 --- a/app/assets/javascripts/admin/addon/components/site-settings/compact-list.hbs +++ b/app/assets/javascripts/admin/addon/components/site-settings/compact-list.hbs @@ -5,4 +5,5 @@ @onChange={{this.onChangeListSetting}} @onChangeChoices={{this.onChangeChoices}} @options={{hash allowAny=this.allowAny}} + @mandatoryValues={{this.setting.mandatory_values}} /> \ No newline at end of file diff --git a/app/assets/javascripts/discourse/tests/integration/components/compact-list-test.js b/app/assets/javascripts/discourse/tests/integration/components/compact-list-test.js new file mode 100644 index 00000000000..74053b75881 --- /dev/null +++ b/app/assets/javascripts/discourse/tests/integration/components/compact-list-test.js @@ -0,0 +1,39 @@ +import EmberObject from "@ember/object"; +import { render } from "@ember/test-helpers"; +import { hbs } from "ember-cli-htmlbars"; +import { module, test } from "qunit"; +import { setupRenderingTest } from "discourse/tests/helpers/component-test"; +import selectKit from "discourse/tests/helpers/select-kit-helper"; + +module("Integration | Component | compact-list site-setting", function (hooks) { + setupRenderingTest(hooks); + + test("mandatory values", async function (assert) { + this.set( + "setting", + EmberObject.create({ + allowsNone: undefined, + category: "foo", + description: "Choose setting", + overridden: false, + placeholder: null, + preview: null, + secret: false, + setting: "foo_bar", + type: "compact_list", + validValues: undefined, + default: "admin", + mandatory_values: "admin", + value: "admin|moderator", + }) + ); + + await render(hbs``); + + const subject = selectKit(".list-setting"); + + await subject.expand(); + + assert.dom(".selected-content button").hasClass("disabled"); + }); +}); diff --git a/app/assets/javascripts/select-kit/addon/components/selected-choice.js b/app/assets/javascripts/select-kit/addon/components/selected-choice.js index abf8b3b5053..07095c5bb5b 100644 --- a/app/assets/javascripts/select-kit/addon/components/selected-choice.js +++ b/app/assets/javascripts/select-kit/addon/components/selected-choice.js @@ -34,6 +34,9 @@ export default class SelectedChoice extends Component.extend(UtilsMixin) { @computed("item") get readOnly() { + if (typeof this.item === "string") { + return this.mandatoryValuesArray.includes(this.item); + } return this.mandatoryValuesArray.includes(this.item.id); } }