added new test for onChange, changed functionality to send the generated tag element and the original input to onChange

This commit is contained in:
Mario Estrada
2011-05-24 19:36:05 -05:00
parent 074d90a6c7
commit fd1e79202f
2 changed files with 16 additions and 7 deletions
+1 -6
View File
@@ -20,7 +20,6 @@
var tags_callbacks = new Array();
$.fn.addTag = function(value,options) {
var options = jQuery.extend({focus:false,callback:true},options);
this.each(function() {
id = $(this).attr('id');
@@ -63,7 +62,6 @@
};
$.fn.removeTag = function(value) {
value = unescape(value);
this.each(function() {
id = $(this).attr('id');
@@ -88,11 +86,9 @@
});
return false;
};
$.fn.tagExist = function(val) {
if (jQuery.inArray(val, $(this)) == -1) {
return false; /* Cannot find value in array */
} else {
@@ -107,7 +103,6 @@
}
$.fn.tagsInput = function(options) {
var settings = jQuery.extend({interactive:true,defaultText:'add a tag',minChars:0,width:'300px',height:'100px','hide':true,'delimiter':',',autocomplete:{selectFirst:false},'unique':true,removeWithBackspace:true},options);
this.each(function() {
@@ -247,7 +242,7 @@
if(tags_callbacks[id] && tags_callbacks[id]['onChange'])
{
var f = tags_callbacks[id]['onChange'];
f(obj);
f(obj, tags[i]);
}
};
+15 -1
View File
@@ -19,7 +19,18 @@
}
$(function() {
$('input.tags').tagsInput();
$('#tags_1').tagsInput();
$('#tags_2').tagsInput({
onChange: function(elem, elem_tags)
{
var languages = ['php','ruby','javascript'];
$('.tag', elem_tags).each(function()
{
if($(this).text().search(new RegExp('\\b(' + languages.join('|') + ')\\b')) >= 0)
$(this).css('background-color', 'yellow');
});
}
});
// Uncomment this line to see the callback functions in action
// $('input.tags').tagsInput({onAddTag:onAddTag,onRemoveTag:onRemoveTag});
@@ -38,6 +49,9 @@
<section>
<form>
<input id="tags_1" type="text" class="tags" value="foo,bar,baz,roffle" />
<label>Technologies: (Programming languages in yellow)</label>
<input id="tags_2" type="text" class="tags" value="php,ios,javascript,ruby,android,kindle" />
</form>
</section>