While drzone88's answer above works great, there is one edge case that I stumbled on which should be brought up: when you search and have no results displayed, the close event is never called. Then your blur function will also never be called. So I settled with setting the flag when response content is empty.
My solution also uses jquery.data() so we don't have to drag a variable around:
$( ".selector" ).autocomplete({
source: ["your values here"],
open: function(event, ui) { $(this).data("no-blur", true); },
close: function(event, ui) {
$(this).data("no-blur", false);
},
response: function(event, ui){
if(ui.content.length == 0) //when search results are empty, close is not called
$(this).data("no-blur", false);
else
$(this).data("no-blur", true); //not sure open is called again either if we re-get results
}
}).on("blur", function() {
if(!$(this).data("no-blur")) {
//do something
}
});
As it turns out, though, because of the order in which events are called and what I actually needed to do (fire something on blur when user blurs the field without selecting an option in the suggestion list), I ended up setting my noblur flag to true at the start of the select function, and back to false at the end of the blur, like so:
$( ".selector" ).autocomplete({
source: ["your values here"],
select: function(ui, event){
$(this).data("no-blur", true);
//do select stuff
},
}).on("blur", function() {
if(!$(this).data("no-blur")) {
//do something
}
$(this).data("no-blur", false);
});
Hope this can help someone!