Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Commit

Permalink
Replace blur bindings with event handlers and parameters specific to …
Browse files Browse the repository at this point in the history
…the jQuery autocomplete library in use.
  • Loading branch information
sebm committed Jun 29, 2011
1 parent 22cb584 commit 6836379
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions jquery.tagsinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

var delimiter = new Array();
var tags_callbacks = new Array();
var gotAutoComplete = false;

$.fn.addTag = function(value,options) {
var options = jQuery.extend({focus:false,callback:true},options);
Expand Down Expand Up @@ -125,9 +124,9 @@
minChars:0,
width:'300px',
height:'100px',
autocomplete: {selectFirst: false },
'hide':true,
'delimiter':',',
autocomplete:{},
'unique':true,
removeWithBackspace:true,
placeholderColor:'#666666'
Expand Down Expand Up @@ -194,32 +193,24 @@
for (attrname in settings.autocomplete) {
autocomplete_options[attrname] = settings.autocomplete[attrname];
}

$(data.fake_input).autocomplete(autocomplete_options).bind('autocompleteselect',data,function(event,ui) {
gotAutoComplete = true;
$(event.data.real_input).addTag(ui.item.value,{focus:true,unique:(settings.unique)});
return false;
});

if (jQuery.Autocompleter !== undefined) {
$(data.fake_input).autocomplete(settings.autocomplete_url, settings.autocomplete);
$(data.fake_input).bind('result',data,function(event,data,formatted) {
if (data) {
d = data + "";
$(event.data.real_input).addTag(d,{focus:true,unique:(settings.unique)});
}
});
} else if (jQuery.ui.autocomplete !== undefined) {
$(data.fake_input).autocomplete(autocomplete_options);
$(data.fake_input).bind('autocompleteselect',data,function(event,ui) {
$(event.data.real_input).addTag(ui.item.value,{focus:true,unique:(settings.unique)});
return false;
});
}


$(data.fake_input).bind('blur',data,function(event) {
setTimeout(function() {
if(gotAutoComplete == true) {
gotAutoComplete = false;
return false;
}
if ( $(event.data.fake_input).val() != $(event.data.fake_input).attr('data-default')) {
if((event.data.minChars <= $(event.data.fake_input).val().length) && (!event.data.maxChars || (event.data.maxChars >= $(event.data.fake_input).val().length))) {
$(event.data.real_input).addTag($(event.data.fake_input).val(),{focus:false,unique:(settings.unique)});
}
}

$(event.data.fake_input).val($(event.data.fake_input).attr('data-default'));
$(event.data.fake_input).css('color',settings.placeholderColor);
}, 100);
return false;
});

} else {
// if a user tabs out of the field, create a new tag
// this is only available if autocomplete is not used.
Expand Down

0 comments on commit 6836379

Please sign in to comment.