Skip to content

Commit 0a04c53

Browse files
committed
feat: show error message for max tags
and max chars
1 parent 99c11ef commit 0a04c53

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

static/lib/composer/tags.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,26 @@ define('composer/tags', function() {
2020
maxTags = ajaxify.data.hasOwnProperty('maxTags') ? ajaxify.data.maxTags : config.maximumTagsPerTopic;
2121

2222
var tagsinput = tagEl.tagsinput({
23-
maxTags: maxTags,
24-
maxChars: config.maximumTagLength,
2523
confirmKeys: [13, 44],
2624
trimValue: true
2725
});
2826
tagsinputEl = tagsinput[0];
2927

3028
tagEl.on('beforeItemAdd', function(event) {
29+
var reachedMaxTags = maxTags && maxTags <= tags.getTags(postContainer.attr('data-uuid')).length;
3130
var cleanTag = utils.cleanUpTag(event.item, config.maximumTagLength);
3231
var different = cleanTag !== event.item;
33-
event.cancel = different || event.item.length < config.minimumTagLength || event.item.length > config.maximumTagLength;
32+
event.cancel = different ||
33+
event.item.length < config.minimumTagLength ||
34+
event.item.length > config.maximumTagLength ||
35+
reachedMaxTags;
36+
3437
if (event.item.length < config.minimumTagLength) {
3538
return app.alertError('[[error:tag-too-short, ' + config.minimumTagLength + ']]');
3639
} else if (event.item.length > config.maximumTagLength) {
3740
return app.alertError('[[error:tag-too-long, ' + config.maximumTagLength + ']]');
41+
} else if (reachedMaxTags) {
42+
return app.alertError('[[error:too-many-tags, ' + maxTags + ']]');
3843
}
3944
if (different) {
4045
tagEl.tagsinput('add', cleanTag);
@@ -133,9 +138,6 @@ define('composer/tags', function() {
133138

134139
minTags = data.minTags;
135140
maxTags = data.maxTags;
136-
if (tagsinputEl) {
137-
tagsinputEl.options.maxTags = maxTags;
138-
}
139141

140142
if (data.tagWhitelist && data.tagWhitelist.length) {
141143
input.attr('readonly', '');

0 commit comments

Comments
 (0)