@@ -32,6 +32,8 @@ class Tribute {
3232 menuItemLimit = null ,
3333 menuShowMinLength = 0 ,
3434 closeOnScroll = false ,
35+ maxDisplayItems = null ,
36+ isBlocked = false
3537 } ) {
3638 this . autocompleteMode = autocompleteMode ;
3739 this . autocompleteSeparator = autocompleteSeparator ;
@@ -119,7 +121,12 @@ class Tribute {
119121
120122 menuItemLimit : menuItemLimit ,
121123
122- menuShowMinLength : menuShowMinLength
124+ menuShowMinLength : menuShowMinLength ,
125+
126+ // Fix for maximum number of items added to the input for the specific Collection
127+ maxDisplayItems : maxDisplayItems ,
128+
129+ isBlocked : isBlocked
123130 }
124131 ] ;
125132 } else if ( collection ) {
@@ -165,7 +172,11 @@ class Tribute {
165172 requireLeadingSpace : item . requireLeadingSpace ,
166173 searchOpts : item . searchOpts || searchOpts ,
167174 menuItemLimit : item . menuItemLimit || menuItemLimit ,
168- menuShowMinLength : item . menuShowMinLength || menuShowMinLength
175+ menuShowMinLength : item . menuShowMinLength || menuShowMinLength ,
176+
177+ // Set maximum number of items added to the input for the specific Collection
178+ maxDisplayItems : item . maxDisplayItems || maxDisplayItems ,
179+ isBlocked : item . isBlocked || isBlocked
169180 } ;
170181 } ) ;
171182 } else {
@@ -281,6 +292,17 @@ class Tribute {
281292 }
282293
283294 showMenuFor ( element , scrollTo ) {
295+ // Check for maximum number of items added to the input for the specific Collection
296+ if (
297+ (
298+ this . current . collection . maxDisplayItems &&
299+ element . querySelectorAll ( '[data-tribute-trigger="' + this . current . collection . trigger + '"]' ) . length >= this . current . collection . maxDisplayItems
300+ ) || this . current . collection . isBlocked
301+ ) {
302+ //console.log("Tribute: Maximum number of items added!");
303+ return ;
304+ }
305+
284306 this . currentMentionTextSnapshot = this . current . mentionText ;
285307
286308 // create the menu if it doesn't exist.
@@ -399,6 +421,17 @@ class Tribute {
399421 }
400422
401423 showMenuForCollection ( element , collectionIndex ) {
424+ // Check for maximum number of items added to the input for the specific Collection
425+ if (
426+ (
427+ this . collection [ collectionIndex || 0 ] . maxDisplayItems &&
428+ element . querySelectorAll ( '[data-tribute-trigger="' + this . collection [ collectionIndex || 0 ] . trigger + '"]' ) . length >= this . collection [ collectionIndex || 0 ] . maxDisplayItems
429+ ) || this . collection [ collectionIndex || 0 ] . isBlocked
430+ ) {
431+ //console.log("Tribute: Maximum number of items added!");
432+ return ;
433+ }
434+
402435 if ( element !== document . activeElement ) {
403436 this . placeCaretAtEnd ( element ) ;
404437 }
0 commit comments