You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jc...@apache.org on 2011/11/25 13:59:29 UTC

svn commit: r1206147 - in /wicket/trunk/wicket-extensions: ./ src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js

Author: jcompagner
Date: Fri Nov 25 12:59:28 2011
New Revision: 1206147

URL: http://svn.apache.org/viewvc?rev=1206147&view=rev
Log:
Wicket autocomplete keeps working on the replaced element when somehow the element is replaced by another ajax request when it is shown.
Issue: WICKET-4261

Modified:
    wicket/trunk/wicket-extensions/   (props changed)
    wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js

Propchange: wicket/trunk/wicket-extensions/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Nov 25 12:59:28 2011
@@ -1,4 +1,5 @@
 /wicket/branches/wicket-1.3.x/jdk-1.4/wicket-extensions:659248,661657,662360,677853,688992,698612,700502,701879,725634,760368,769440,772653,786424,790850
 /wicket/branches/wicket-1.4.x/wicket-extensions:963681
+/wicket/branches/wicket-1.5.x/wicket-extensions:1204465,1206145
 /wicket/sandbox/jthomerson/experimental/wicket-devutils/wicket-extensions:760296-760351,760353-760355
 /wicket/trunk/wicket-devutils/wicket-extensions:760352

Modified: wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js?rev=1206147&r1=1206146&r2=1206147&view=diff
==============================================================================
--- wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js (original)
+++ wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js Fri Nov 25 12:59:28 2011
@@ -53,6 +53,7 @@ Wicket.AutoComplete=function(elementId, 
 	var objonchange;
 	var objonchangeoriginal;
 	var objonfocus;
+	var initialElement; 
 	
 	// holds the eventual margins, padding, etc. of the menu container.
 	// it is computed when the menu is first rendered, and then reused.
@@ -77,17 +78,20 @@ Wicket.AutoComplete=function(elementId, 
 	var throttleDelay = cfg.throttleDelay;
 
     function initialize(){
+    	var isShowing = false;
 		// Remove the autocompletion menu if still present from
 		// a previous call. This is required to properly register
 		// the mouse event handler again (using the new stateful 'mouseactive'
 		// variable which just gets created)
         var choiceDiv=document.getElementById(getMenuId());
         if (choiceDiv != null) {
+        	isShowing = choiceDiv.showingAutocomplete;
             choiceDiv.parentNode.parentNode.removeChild(choiceDiv.parentNode);
         } 
         	
         var obj = Wicket.$(elementId);
-
+		initialElement = obj;
+		
         objonkeydown=obj.onkeydown;
         objonblur=obj.onblur;
         objonkeyup=obj.onkeyup;
@@ -118,6 +122,7 @@ Wicket.AutoComplete=function(elementId, 
                 return killEvent(event);
             }
             if (!ignoreOneFocusGain && cfg.showListOnFocusGain && visible==0) {
+            	getAutocompleteMenu().showingAutocomplete = true;
                 if (cfg.showCompleteListOnFocusGain) {
                     updateChoices(true);
                 } else {
@@ -209,6 +214,29 @@ Wicket.AutoComplete=function(elementId, 
             }
 			if(typeof objonkeypress=="function") return objonkeypress.apply(this,[event]);
         }
+        if (Wicket.Focus.getFocusedElement() === obj && isShowing == true)
+        {
+        	// element already has focus, we should show list
+        	if (cfg.showListOnFocusGain) {
+                if (cfg.showCompleteListOnFocusGain) {
+                    updateChoices(true);
+                } else {
+                    updateChoices();
+                }
+            }
+        }
+    }
+    
+    function clearMenu()
+    {
+    	// Remove the autocompletion menu if still present from
+		// a previous call. This is required to properly register
+		// the mouse event handler again (using the new stateful 'mouseactive'
+		// variable which just gets created)
+        var choiceDiv=document.getElementById(getMenuId());
+        if (choiceDiv != null) {
+            choiceDiv.parentNode.parentNode.removeChild(choiceDiv.parentNode);
+        } 
     }
     
     function setSelected(newSelected) {
@@ -555,13 +583,19 @@ Wicket.AutoComplete=function(elementId, 
     }
     
     function doUpdateChoices(resp){
-    
-    	// check if the input hasn't been cleared in the meanwhile
+    	
+    	getAutocompleteMenu().showingAutocomplete = false;
+    	
+    	// check if the input hasn't been cleared in the meanwhile or has been replaced by ajax
 	var input=Wicket.$(elementId);
-   		if ((document.activeElement != input) || !cfg.showListOnEmptyInput && (input.value==null || input.value=="")) {
+   		if ((input != initialElement) || (document.activeElement != input) || !cfg.showListOnEmptyInput && (input.value==null || input.value=="")) {
    			hideAutoComplete();
 			Wicket.Ajax.invokePostCallHandlers();
    			hideIndicator();
+   			if (input != initialElement)
+   			{
+   				clearMenu();
+   			}
    			return;
    		}