From 6bee972a5cebf9dccdf969f2936351cb23c641c6 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 5 Feb 2020 17:47:20 +0100 Subject: [PATCH] FIX: corrects min/max logic for mini-tag-chooser (#8871) --- .../components/mini-tag-chooser.js.es6 | 20 +++++++++++-------- .../select-kit/components/select-kit.js.es6 | 2 +- .../javascripts/select-kit/mixins/tags.js.es6 | 3 ++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6 b/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6 index 9c25173b2c2..e7471b0e508 100644 --- a/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6 +++ b/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6 @@ -69,7 +69,9 @@ export default ComboBox.extend(TagsMixin, { maximumSelectedTags: computed(function() { return parseInt( - this.options.limit || this.options.maximum || this.maxTagsPerTopic, + this.options.limit || + this.selectKit.options.maximum || + this.maxTagsPerTopic, 10 ); }), @@ -81,7 +83,8 @@ export default ComboBox.extend(TagsMixin, { }, caretIcon: computed("value.[]", function() { - return this.selectKit.options.maximum >= makeArray(this.value).length + const maximum = this.selectKit.options.maximum; + return maximum && makeArray(this.value).length >= parseInt(maximum, 10) ? null : "plus"; }), @@ -89,18 +92,19 @@ export default ComboBox.extend(TagsMixin, { modifySelection(content) { let joinedTags = makeArray(this.value).join(", "); - if (!this.selectKit.options.maximum >= makeArray(this.value).length) { + const minimum = this.selectKit.options.minimum; + if (minimum && makeArray(this.value).length < parseInt(minimum, 10)) { const key = this.selectKit.options.minimumLabel || "select_kit.min_content_not_reached"; const label = I18n.t(key, { count: this.selectKit.options.minimum }); content.title = content.name = content.label = label; - } + } else { + content.title = content.name = content.value = content.label = joinedTags; - content.title = content.name = content.value = content.label = joinedTags; - - if (content.label.length > 32) { - content.label = `${content.label.slice(0, 32)}...`; + if (content.label.length > 32) { + content.label = `${content.label.slice(0, 32)}...`; + } } return content; diff --git a/app/assets/javascripts/select-kit/components/select-kit.js.es6 b/app/assets/javascripts/select-kit/components/select-kit.js.es6 index 333a8438a7d..f7244716bae 100644 --- a/app/assets/javascripts/select-kit/components/select-kit.js.es6 +++ b/app/assets/javascripts/select-kit/components/select-kit.js.es6 @@ -255,9 +255,9 @@ export default Component.extend( icon: null, icons: null, maximum: null, + maximumLabel: null, minimum: null, minimumLabel: null, - maximumLabel: null, autoInsertNoneItem: true, clearOnClick: false, closeOnChange: true, diff --git a/app/assets/javascripts/select-kit/mixins/tags.js.es6 b/app/assets/javascripts/select-kit/mixins/tags.js.es6 index 22198a25bb8..1477278f62b 100644 --- a/app/assets/javascripts/select-kit/mixins/tags.js.es6 +++ b/app/assets/javascripts/select-kit/mixins/tags.js.es6 @@ -24,7 +24,8 @@ export default Mixin.create({ allowAnyTag: reads("site.can_create_tag"), validateCreate(filter, content) { - if (this.selectKit.options.maximum >= makeArray(this.value).length) { + const maximum = this.selectKit.options.maximum; + if (maximum && makeArray(this.value).length >= parseInt(maximum, 10)) { this.addError( I18n.t("select_kit.max_content_reached", { count: this.selectKit.limit