diff --git a/README.md b/README.md index a8abe7a..d821340 100644 --- a/README.md +++ b/README.md @@ -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 }); diff --git a/src/jquery.tagsinput.js b/src/jquery.tagsinput.js index b6c75e4..e1c73c1 100644 --- a/src/jquery.tagsinput.js +++ b/src/jquery.tagsinput.js @@ -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'); @@ -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 = '
';