Added support for remove tack with backspace

This commit is contained in:
Mario Estrada
2011-05-20 19:29:57 -05:00
parent ba418a2092
commit 74520e1cbb
+13 -1
View File
@@ -108,7 +108,7 @@
jQuery.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},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() {
if (settings.hide) {
@@ -212,6 +212,18 @@
return false;
}
});
//Delete last tag on backspace
data.removeWithBackspace && $(data.fake_input).bind('keyup', function(event)
{
if(event.keyCode == 8 && $(this).val() == '')
{
var last_tag = $(this).closest('.tagsinput').find('.tag:last').text();
var id = $(this).attr('id').replace(/_tag$/, '');
last_tag = last_tag.replace(/[\s]+x$/, '');
$('#' + id).removeTag(escape(last_tag));
$(this).trigger('focus');
};
});
$(data.fake_input).blur();
} // if settings.interactive
return false;