diff --git a/examples.html b/examples.html index 90113216..aa793990 100644 --- a/examples.html +++ b/examples.html @@ -58,6 +58,11 @@ availableTags: sampleTags }); + $("#singleFieldTagsWithTagLengthLimit").tagit({ + availableTags: sampleTags, + tagLengthLimit: 5, + }); + //------------------------------- // Preloading data in markup //------------------------------- @@ -189,6 +194,24 @@
You can already do multiword tags with spaces in them by default, but those must be wrapped in quotes. This option lets you use spaces without requiring the user to quote the input.
There are normally 5 ways to insert a tag after inputting some text: space, comma, enter, selecting an autocomplete option, or defocusing the widget. With the "allowSpaces" option set to true, space no longer inserts a tag, it just adds a space to the current tag input.
diff --git a/js/tag-it.js b/js/tag-it.js index 078c264f..b5c3dc99 100644 --- a/js/tag-it.js +++ b/js/tag-it.js @@ -35,6 +35,7 @@ readOnly : false, // Disables editing. removeConfirmation: false, // Require confirmation to remove tags. tagLimit : null, // Max number of tags allowed (null for unlimited). + tagLengthLimit : null, // Used for autocomplete, unless you override `autocomplete.source`. availableTags : [], @@ -467,6 +468,10 @@ return false; } + if (this.options.tagLengthLimit && this.tagInput.val().length > this.options.tagLengthLimit) { + return false; + } + var label = $(this.options.onTagClicked ? '' : '').text(value); // Create tag.