@@ -31,8 +31,10 @@ class Tribute {
3131 searchOpts = { } ,
3232 menuItemLimit = null ,
3333 menuShowMinLength = 0 ,
34- closeOnScroll = false
35- } ) {
34+ closeOnScroll = false ,
35+ maxDisplayItems = null ,
36+ isBlocked = false
37+ } ) {
3638 this . autocompleteMode = autocompleteMode ;
3739 this . autocompleteSeparator = autocompleteSeparator ;
3840 this . menuSelected = 0 ;
@@ -119,8 +121,13 @@ class Tribute {
119121
120122 menuItemLimit : menuItemLimit ,
121123
122- menuShowMinLength : menuShowMinLength
123- }
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
130+ }
124131 ] ;
125132 } else if ( collection ) {
126133 if ( this . autocompleteMode )
@@ -164,7 +171,11 @@ class Tribute {
164171 requireLeadingSpace : item . requireLeadingSpace ,
165172 searchOpts : item . searchOpts || searchOpts ,
166173 menuItemLimit : item . menuItemLimit || menuItemLimit ,
167- menuShowMinLength : item . menuShowMinLength || menuShowMinLength
174+ menuShowMinLength : item . menuShowMinLength || menuShowMinLength ,
175+
176+ // Set maximum number of items added to the input for the specific Collection
177+ maxDisplayItems : item . maxDisplayItems || maxDisplayItems ,
178+ isBlocked : item . isBlocked || isBlocked
168179 } ;
169180 } ) ;
170181 } else {
@@ -282,6 +293,17 @@ class Tribute {
282293 }
283294
284295 showMenuFor ( element , scrollTo ) {
296+ // Check for maximum number of items added to the input for the specific Collection
297+ if (
298+ (
299+ this . current . collection . maxDisplayItems &&
300+ element . querySelectorAll ( '[data-tribute-trigger="' + this . current . collection . trigger + '"]' ) . length >= this . current . collection . maxDisplayItems
301+ ) || this . current . collection . isBlocked
302+ ) {
303+ //console.log("Tribute: Maximum number of items added!");
304+ return ;
305+ }
306+
285307 this . currentMentionTextSnapshot = this . current . mentionText ;
286308
287309 // create the menu if it doesn't exist.
@@ -400,6 +422,16 @@ class Tribute {
400422 }
401423
402424 showMenuForCollection ( element , collectionIndex ) {
425+ // Check for maximum number of items added to the input for the specific Collection
426+ if (
427+ (
428+ this . collection [ collectionIndex || 0 ] . maxDisplayItems &&
429+ element . querySelectorAll ( '[data-tribute-trigger="' + this . collection [ collectionIndex || 0 ] . trigger + '"]' ) . length >= this . collection [ collectionIndex || 0 ] . maxDisplayItems
430+ ) || this . collection [ collectionIndex || 0 ] . isBlocked
431+ ) {
432+ //console.log("Tribute: Maximum number of items added!");
433+ return ;
434+ }
403435
404436 if ( element !== document . activeElement ) {
405437 this . placeCaretAtEnd ( element ) ;
0 commit comments