From 14d7822322dab968ef5a473289e4c70b9e7ce356 Mon Sep 17 00:00:00 2001 From: mohsenksr Date: Sun, 20 Dec 2020 22:40:30 +0330 Subject: [PATCH] tagLengthLimit added --- examples.html | 23 +++++++++++++++++++++++ js/tag-it.js | 5 +++++ 2 files changed, 28 insertions(+) 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 @@

Single Input Field (2)


+ + +

+ Single Input Field with + tagLengthLimit +

+
+

with tag length limit. Here tagLengthLimit is 5

+ +
+ +
+ +

Spaces Allowed Without Quotes

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.