@@ -31,8 +31,10 @@ class Tribute {
31
31
searchOpts = { } ,
32
32
menuItemLimit = null ,
33
33
menuShowMinLength = 0 ,
34
- closeOnScroll = false
35
- } ) {
34
+ closeOnScroll = false ,
35
+ maxDisplayItems = null ,
36
+ isBlocked = false
37
+ } ) {
36
38
this . autocompleteMode = autocompleteMode ;
37
39
this . autocompleteSeparator = autocompleteSeparator ;
38
40
this . menuSelected = 0 ;
@@ -119,8 +121,13 @@ class Tribute {
119
121
120
122
menuItemLimit : menuItemLimit ,
121
123
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
+ }
124
131
] ;
125
132
} else if ( collection ) {
126
133
if ( this . autocompleteMode )
@@ -164,7 +171,11 @@ class Tribute {
164
171
requireLeadingSpace : item . requireLeadingSpace ,
165
172
searchOpts : item . searchOpts || searchOpts ,
166
173
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
168
179
} ;
169
180
} ) ;
170
181
} else {
@@ -282,6 +293,17 @@ class Tribute {
282
293
}
283
294
284
295
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
+
285
307
this . currentMentionTextSnapshot = this . current . mentionText ;
286
308
287
309
// create the menu if it doesn't exist.
@@ -400,6 +422,16 @@ class Tribute {
400
422
}
401
423
402
424
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
+ }
403
435
404
436
if ( element !== document . activeElement ) {
405
437
this . placeCaretAtEnd ( element ) ;
0 commit comments