$(function() {
$('#form-tags-1').tagsInput();
$('#form-tags-2').tagsInput({
'onAddTag': function(input, value) {
console.log('tag added', input, value);
},
'onRemoveTag': function(input, value) {
console.log('tag removed', input, value);
},
'onChange': function(input, value) {
console.log('change triggered', input, value);
}
});
$('#form-tags-3').tagsInput({
'unique': true,
'minChars': 2,
'maxChars': 10,
'limit': 5,
'validationPattern': new RegExp('^[a-zA-Z]+$')
});
$('#form-tags-4').tagsInput({
'autocomplete': {
source: [
'apple',
'banana',
'orange',
'pizza'
]
}
});
$('#form-tags-5').tagsInput({
'delimiter': ';'
});
$('#form-tags-6').tagsInput({
'delimiter': [',', ';']
});
});
/* jQuery Tags Input Revisited Plugin
*
* Copyright (c) Krzysztof Rusnarczyk
* Licensed under the MIT license */
(function($) {
var delimiter = [];
var inputSettings = [];
var callbacks = [];
$.fn.addTag = function(value, options) {
options = jQuery.extend({
focus: false,
callback: true
}, options);
this.each(function() {
var id = $(this).attr('id');
var tagslist = $(this).val().split(_getDelimiter(delimiter[id]));
if (tagslist[0] === '') tagslist = [];
value = jQuery.trim(value);
if ((inputSettings[id].unique && $(this).tagExist(value)) || !_validateTag(value, inputSettings[id], tagslist, delimiter[id])) {
$('#' + id + '_tag').addClass('error');
return false;
}
$('', {class: 'tag'}).append(
$('', {class: 'tag-text'}).text(value),
$('