HTML_QuickForm_livesearch_select call orders

From: Date: Mon, 18 Sep 2006 09:36:50 +0000
Subject: HTML_QuickForm_livesearch_select call orders
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-25159@lists.php.net to get a copy of this message
Hi all, I've just installed HTML_QuickForm_livesearch_select and I've configured it to search in a database. I found a little problem on using it, a problem that is very simple to understand but very complicated to explain... well, I'll try to explain it even if the English is not my mother tongue: every key pressed perform a livesearch and normally lesser keys pressed return more rows (and more time to collect them). So very often happens that the last result is relative to one of the first keys the user has pressed and so the result is not coherent to the user input... I have tried to solve the problem in this way $ diff -U 3 livesearch_select.php /usr/share/php/HTML/QuickForm/livesearch_select.php
--- livesearch_select.php       2006-09-18 09:34:06.044016376 +0200
+++ /usr/share/php/HTML/QuickForm/livesearch_select.php 2006-09-18 11:26:50.277696552 +0200
@@ -295,9 +295,11 @@ </style> <script type='text/javascript' src="auto_server.php?client=Util,main,dispatcher,httpclient,request,json,loading,queues,QfLiveSearch&stub=livesearch"></script> <script type='text/javascript'>//<![CDATA[ +self.livesearch_callId = 0; callback = {}; function searchRequest(searchBox, callfunc) {
-    eval("remoteLiveSearch."+callfunc+"(searchBox.value)");
+    self.livesearch_callId++;
+ eval("remoteLiveSearch."+callfunc+"(searchBox.value,self.livesearch_callId)");
} //]]> </script> @@ -309,10 +311,12 @@
             $scriptLoad .= '
<script type="text/javascript">//<![CDATA[ callback.'.$this->_options['elementId'].' = function(result) {
+    if (result[\'livesearch_callId\'] && (self.livesearch_callId != result[\'livesearch_callId\'])) return;
     var  res = document.getElementById(\''.$this->getName().'Result\');
     res.style.display = "block";
     var out = "<?xml version=\'1.0\' encoding=\'utf-8\'  ?><ul class=\"outerUl\" >";
     for(var i in result) {
+        if (i == \'livesearch_callId\') continue;
         if (i != \'______array\') {
             out += "<li class=\"outerLi\"><a href=\"#\" value=\""+i+"\" text=\""+result[i]+"\" onmouseover=\"liveSearchHover(this);\" onmousedown=\"liveSearchClicked(this.getAttribute(\'value\'), this.getAttribute(\'text\'), \''.$this->_options['elementId'].'\', \''.$this->realName.'\');\">"+result[i]+"</a></li>";
         }
Obviously the search method in the class have to add the liveselect_callId key to the returned array. I know is not an elegant solution but it works.

« previous php.pear.general (#25159) next »