Skip to content

A platform for community discussion. Free, open, simple.

FIX: Show max tag error and prevent search (#26233)

Natalie Tayf30cc5ebed9a
diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/mini-tag-chooser-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/mini-tag-chooser-test.js
index ec336a5ce70..beaeac77581 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/mini-tag-chooser-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/mini-tag-chooser-test.js
@@ -67,6 +67,29 @@ module(
);
});
+ test("disables search and shows limit when max_tags_per_topic is zero", async function (assert) {
+ this.set("value", ["cat", "kit"]);
+ this.siteSettings.max_tags_per_topic = 0;
+
+ await render(hbs`<MiniTagChooser @value={{this.value}} />`);
+
+ assert.strictEqual(this.subject.header().value(), "cat,kit");
+ await this.subject.expand();
+
+ const error = query(".select-kit-error").innerText;
+ assert.strictEqual(
+ error,
+ I18n.t("select_kit.max_content_reached", {
+ count: 0,
+ })
+ );
+ await this.subject.fillInFilter("dawg");
+ assert.notOk(
+ exists(".select-kit-collection .select-kit-row"),
+ "it doesn’t show any options"
+ );
+ });
+
test("required_tag_group", async function (assert) {
this.set("value", ["foo", "bar"]);
diff --git a/app/assets/javascripts/select-kit/addon/components/mini-tag-chooser.js b/app/assets/javascripts/select-kit/addon/components/mini-tag-chooser.js
index ef8ab199058..62bc2acb6b0 100644
--- a/app/assets/javascripts/select-kit/addon/components/mini-tag-chooser.js
+++ b/app/assets/javascripts/select-kit/addon/components/mini-tag-chooser.js
@@ -70,6 +70,13 @@ export default MultiSelectComponent.extend(TagsMixin, {
}),
search(filter) {
+ const maximum = this.selectKit.options.maximum;
+ if (maximum === 0) {
+ const key = "select_kit.max_content_reached";
+ this.addError(I18n.t(key, { count: maximum }));
+ return [];
+ }
+
const data = {
q: filter || "",
limit: this.maxTagSearchResults,
diff --git a/app/assets/javascripts/select-kit/addon/components/select-kit.js b/app/assets/javascripts/select-kit/addon/components/select-kit.js
index 3b9dbd651a9..d7fc79ad70b 100644
--- a/app/assets/javascripts/select-kit/addon/components/select-kit.js
+++ b/app/assets/javascripts/select-kit/addon/components/select-kit.js
@@ -371,7 +371,9 @@ export default Component.extend(
},
addError(error) {
- this.errorsCollection.pushObject(error);
+ if (!this.errorsCollection.includes(error)) {
+ this.errorsCollection.pushObject(error);
+ }
this._safeAfterRender(() => this.popper && this.popper.update());
},
@@ -649,6 +651,12 @@ export default Component.extend(
return [];
}
+ if (this.selectKit.options.maximum === 0) {
+ this.set("selectKit.isLoading", false);
+ this.set("selectKit.hasNoContent", false);
+ return [];
+ }
+
content = content.concat(makeArray(result));
content = this.selectKit.modifyContent(content).filter(Boolean);