Need to unregister the blur handler when showing the KNL
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 23 May 2010 20:30:42 +0000 (16:30 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 23 May 2010 20:30:42 +0000 (16:30 -0400)
Showing the KNL causing the trigger to blur, triggering the code that
adds the current value to the prettyautocompleter's list.

horde/js/prettyautocomplete.js

index c1db325..069c4bd 100644 (file)
@@ -47,9 +47,11 @@ var PrettyAutocompleter = Class.create({
         // Build the DOM structure
         this.buildStructure();
 
+        // Remember the bound method to unregister later.
+        this._boundProcessValue = this._processValue.bind(this);
         var trigger = $(this.p.trigger);
         trigger.observe('keydown', this._onKeyDown.bindAsEventListener(this));
-        trigger.observe('blur', this._processValue.bind(this));
+        trigger.observe('blur', this._boundProcessValue);
 
         // Make sure the p.items element is hidden
         if (!this.p.debug) {
@@ -69,6 +71,9 @@ var PrettyAutocompleter = Class.create({
         // Create the underlaying Autocompleter
         this.p.uri += '/input=' + this.p.trigger;
 
+        this.p.onShow = this._knvShow.bind(this);
+        this.p.onHide = this._knvHide.bind(this);
+
         // Make sure the knl is contained in the overlay
         this.p.domParent = this.p.box;
         new Ajax.Autocompleter(this.p.trigger, this.p.uri, this.p);
@@ -258,6 +263,15 @@ var PrettyAutocompleter = Class.create({
             c = c.without(item.displayValue);
         });
         return c;
-    }
+    },
+
+    _knvShow: function(l)
+    {
+        $(this.p.trigger).stopObserving('blur', this._boundProcessValue);
+    },
 
+    _knvHide: function(l)
+    {
+        $(this.p.trigger).observe('blur', this._boundProcessValue);
+    }
 });