From 5a0f4106efd8dc5be5a861b51a09cb1ff7966de9 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 9 Oct 2013 17:08:45 +0200 Subject: [PATCH] Automatically remove the autocompleter when the attached-to form field loses focus --- public_html/static/js/jquery-autocomplete.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/public_html/static/js/jquery-autocomplete.js b/public_html/static/js/jquery-autocomplete.js index 5ccf1d0..bccd7b4 100644 --- a/public_html/static/js/jquery-autocomplete.js +++ b/public_html/static/js/jquery-autocomplete.js @@ -271,13 +271,24 @@ AutoCompleterInstance.prototype.show = function() { } }; + var removal_hook = function(){ + var autocompleter = $(this).data("attached-autocomplete"); + + if(autocompleter) + { + autocompleter.remove(); + } + } + if(persistent === true) { this.on("input.autocomplete_hook", selector, event); + this.on("blur.autocomplete_hook", selector, removal_hook); } else { this.on("input.autocomplete_hook", event); + this.on("blur.autocomplete_hook", removal_hook); } return this;