Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
availableTags: sampleTags
});

$("#singleFieldTagsWithTagLengthLimit").tagit({
availableTags: sampleTags,
tagLengthLimit: 5,
});

//-------------------------------
// Preloading data in markup
//-------------------------------
Expand Down Expand Up @@ -189,6 +194,24 @@ <h3><a name="graceful-degredation"></a>Single Input Field (2)</h3>
</form>

<hr>


<h3>
<a name="graceful-degredation"></a>Single Input Field with
tagLengthLimit
</h3>
<form>
<p>with tag length limit. Here tagLengthLimit is 5</p>
<input
name="tags"
id="singleFieldTagsWithTagLengthLimit"
value="Apple, Orange"
/>
</form>

<hr />


<h3>Spaces Allowed Without Quotes</h3>
<p>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.</p>
<p>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.</p>
Expand Down
5 changes: 5 additions & 0 deletions js/tag-it.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : [],
Expand Down Expand Up @@ -467,6 +468,10 @@
return false;
}

if (this.options.tagLengthLimit && this.tagInput.val().length > this.options.tagLengthLimit) {
return false;
}

var label = $(this.options.onTagClicked ? '<a class="tagit-label"></a>' : '<span class="tagit-label"></span>').text(value);

// Create tag.
Expand Down