From 49fc5f3ab11f9cb24d41fa849ee50cc3203e8943 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Tue, 15 Nov 2011 11:41:58 -0800 Subject: [PATCH] fix to issue #28 https://github.com/xoxco/jQuery-Tags-Input/issues/28 onChange now receives the tag added or removed. --- jquery.tagsinput.js | 2 +- test.html | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/jquery.tagsinput.js b/jquery.tagsinput.js index 758c49d..bb274ef 100644 --- a/jquery.tagsinput.js +++ b/jquery.tagsinput.js @@ -126,7 +126,7 @@ { var i = tagslist.length; var f = tags_callbacks[id]['onChange']; - f.call(this, $(this), tagslist[i]); + f.call(this, $(this), tagslist[i-1]); } } diff --git a/test.html b/test.html index 4b89f6e..dbe6719 100644 --- a/test.html +++ b/test.html @@ -25,7 +25,12 @@ alert("Removed a tag: " + tag); } + function onChangeTag(input,tag) { + alert("Changed a tag: " + tag); + } + $(function() { + $('#tags_1').tagsInput(); $('#tags_2').tagsInput({ onChange: function(elem, elem_tags) @@ -43,8 +48,9 @@ autocomplete_url:'test/fake_json_endpoint.html' // jquery ui autocomplete requires a json endpoint }); + // Uncomment this line to see the callback functions in action -// $('input.tags').tagsInput({onAddTag:onAddTag,onRemoveTag:onRemoveTag}); +// $('input.tags').tagsInput({onAddTag:onAddTag,onRemoveTag:onRemoveTag,onChange: onChangeTag}); // Uncomment this line to see an input with no interface for adding new tags. // $('input.tags').tagsInput({interactive:false});