FIX: corrects min/max logic for mini-tag-chooser (#8871)

This commit is contained in:
Joffrey JAFFEUX 2020-02-05 17:47:20 +01:00 committed by GitHub
parent 6253ddc74e
commit 6bee972a5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 10 deletions

View File

@ -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;

View File

@ -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,

View File

@ -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