Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Added tagValidator function. #331

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@ option to false.
'removeWithBackspace' : true,
'minChars' : 0,
'maxChars' : 0, // if not provided there is no limit
'placeholderColor' : '#666666'
'placeholderColor' : '#666666',
'tagValidator': callback_function // function to validate a tag before it becomes a tag
});
6 changes: 5 additions & 1 deletion src/jquery.tagsinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@

if (options.unique) {
var skipTag = $(this).tagExist(value);
if(!skipTag && tags_callbacks[id]['tagValidator']){
skipTag = !tags_callbacks[id]['tagValidator'](value);
}
if(skipTag == true) {
//Marks fake input as not_valid to let styling it
$('#'+id+'_tag').addClass('not_valid');
Expand Down Expand Up @@ -221,11 +224,12 @@

delimiter[id] = data.delimiter;

if (settings.onAddTag || settings.onRemoveTag || settings.onChange) {
if (settings.onAddTag || settings.onRemoveTag || settings.onChange || settings.tagValidator) {
tags_callbacks[id] = new Array();
tags_callbacks[id]['onAddTag'] = settings.onAddTag;
tags_callbacks[id]['onRemoveTag'] = settings.onRemoveTag;
tags_callbacks[id]['onChange'] = settings.onChange;
tags_callbacks[id]['tagValidator'] = settings.tagValidator;
}

var markup = '<div id="'+id+'_tagsinput" class="tagsinput"><div id="'+id+'_addTag">';
Expand Down