Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added/Modified events:

OnAdding: replaces OnAdded - fires before tag is added
OnAdded: fires after tag has been added
OnRemoving: replaces OnRemoved - fires before tag is removed
OnRemoved: fires after tag has been removed
OnBlur: fires on input field blur event
  • Loading branch information...
commit 0d86b5f5b78a1980ac808f13211c4e12515173ea 1 parent 6f32cc9
@chemass authored
Showing with 24 additions and 8 deletions.
  1. +12 −3 examples.html
  2. +12 −5 js/tag-it.js
View
15 examples.html
@@ -69,18 +69,27 @@
var eventTags = $('#eventTags');
eventTags.tagit({
availableTags: sampleTags,
- onTagRemoved: function(evt, tag) {
+ onTagRemoving: function(evt, tag) {
console.log(evt);
alert('This tag is being removed: ' + eventTags.tagit('tagLabel', tag));
},
+ onTagRemoved: function(evt, tag) {
+ console.log(evt);
+ alert('This tag has been removed: ' + eventTags.tagit('tagLabel', tag));
+ },
onTagClicked: function(evt, tag) {
console.log(tag);
alert('This tag was clicked: ' + eventTags.tagit('tagLabel', tag));
- }
+ },
+ onBlur: function(){ alert('Blur event'); }
+ }).tagit('option', 'onTagAdding', function(evt, tag) {
+ // Add this callbackafter we initialize the widget,
+ // so that onTagAdding doesn't get called on page load.
+ alert('This tag is being added: ' + eventTags.tagit('tagLabel', tag));
}).tagit('option', 'onTagAdded', function(evt, tag) {
// Add this callbackafter we initialize the widget,
// so that onTagAdded doesn't get called on page load.
- alert('This tag is being added: ' + eventTags.tagit('tagLabel', tag));
+ alert('This tag has been added: ' + eventTags.tagit('tagLabel', tag));
});
//-------------------------------
View
17 js/tag-it.js
@@ -74,9 +74,12 @@
// Event callbacks.
- onTagAdded : null,
+ onTagAdding: null,
+ onTagAdded: null,
+ onTagRemoving: null,
onTagRemoved: null,
- onTagClicked: null
+ onTagClicked: null,
+ onBlur: null
},
@@ -97,7 +100,7 @@
this.tagList = this.element.find('ul, ol').andSelf().last();
}
- this._tagInput = $('<input type="text" />').addClass('ui-widget-content');
+ this._tagInput = $('<input type="text" />').addClass('ui-widget-content').blur(function () { that._trigger('onBlur', null) });
if (this.options.tabIndex) {
this._tagInput.attr('tabindex', this.options.tabIndex);
}
@@ -343,13 +346,15 @@
tag.append('<input type="hidden" style="display:none;" value="' + escapedValue + '" name="' + this.options.itemName + '[' + this.options.fieldName + '][]" />');
}
- this._trigger('onTagAdded', null, tag);
+ this._trigger('onTagAdding', null, tag);
// Cleaning the input.
this._tagInput.val('');
// insert tag
this._tagInput.parent().before(tag);
+
+ this._trigger('onTagAdded', null, tag);
},
removeTag: function(tag, animate) {
@@ -357,7 +362,7 @@
tag = $(tag);
- this._trigger('onTagRemoved', null, tag);
+ this._trigger('onTagRemoving', null, tag);
if (this.options.singleField) {
var tags = this.assignedTags();
@@ -375,6 +380,8 @@
} else {
tag.remove();
}
+
+ this._trigger('onTagRemoved', null, tag);
},
removeAll: function() {
Please sign in to comment.
Something went wrong with that request. Please try again.