if (typeof item === "object" && !self.objectItems)
throw("Can't add objects when itemValue option is not set");
- // Ignore strings only containg whitespace
+ // Ignore strings only containing whitespace
if (item.toString().match(/^\s*$/))
return;
itemTitle = self.options.itemTitle(item),
itemThumb = self.options.itemThumb(item);
- // Ignore items allready added
+ // Ignore items already added
var existing = $.grep(self.itemsArray, function(item) { return self.options.itemValue(item) === itemValue; } )[0];
if (existing && !self.options.allowDuplicates) {
// Invoke onTagExists
// add <option /> if item represents a value not present in one of the <select />'s options
if (self.isSelect && !optionExists) {
- var $option = $('<option selected>' + htmlEncode(itemText) + '</option>');
+ var $option = $('<option>' + htmlEncode(itemText) + '</option>');
$option.data('item', item);
$option.attr('value', itemValue);
self.$element.append($option);
},
/**
- * Removes all tagsinput behaviour and unregsiter all event handlers
+ * Removes all tagsinput behaviour and unregister all event handlers
*/
destroy: function() {
var self = this;
var tagsinput = $(this).data('tagsinput');
// Initialize a new tags input
if (!tagsinput) {
- tagsinput = new TagsInput(this, arg1);
- $(this).data('tagsinput', tagsinput);
- results.push(tagsinput);
-
- if (this.tagName === 'SELECT') {
- $('option', $(this)).attr('selected', 'selected');
- }
-
- // Init tags from $(this).val()
- $(this).val($(this).val());
+ tagsinput = new TagsInput(this, arg1);
+ $(this).data('tagsinput', tagsinput);
+ results.push(tagsinput);
+ // Init tags from $(this).val()
+ $(this).val($(this).val());
} else if (!arg1 && !arg2) {
- // tagsinput already exists
- // no function, trying to init
- results.push(tagsinput);
+ // tagsinput already exists
+ // no function, trying to init
+ results.push(tagsinput);
} else if(tagsinput[arg1] !== undefined) {
- // Invoke function on existing tags input
- if(tagsinput[arg1].length === 3 && arg3 !== undefined){
- var retVal = tagsinput[arg1](arg2, null, arg3);
- }else{
- var retVal = tagsinput[arg1](arg2);
- }
- if (retVal !== undefined)
- results.push(retVal);
+ // Invoke function on existing tags input
+ if(tagsinput[arg1].length === 3 && arg3 !== undefined){
+ var retVal = tagsinput[arg1](arg2, null, arg3);
+ }else{
+ var retVal = tagsinput[arg1](arg2);
+ }
+ if (retVal !== undefined)
+ results.push(retVal);
}
});