Hi,
I have noticed that on slow network connection it is quite easy to 'flood’
the ajax select widget, because it currently sends a request each time the
user press a key. On slow networks, users tend to press a lot of keys before
getting any response from the server and things don’t work as they should. I
propose to implement a timer that would prevent requests to be sent to the
server when the user is still typing. In my own tests, I have found that a
timer of 300ms seems appropriate and the server will only get a request when
the user pauses typing.
My proposed patch for this is below, and improves the behaviour of the
application in most cases (tested on firefox). Please let me know what you
think.
Further improvement could include: cancelling processing responses from the
server once the user has left the widget, and caching data. This is not
implemented yet.
Regards
Raphael
<<<Start of the patch file
— ajax_select_orig.js 2008-05-26 19:49:03.000000000 +1100
+++ ajax_select.js 2008-05-26 19:49:05.000000000 +1100
@@ -17,6 +17,8 @@
//xajaxDebug = 1;
var current_app = ‘etemplate’;
+var ajax_select_timer_id = 0;
+var ajax_select_timeout = 300;
function ajax_select_widget_setup(widget_id, onchange, options, currentapp)
{
current_app = currentapp;
@@ -47,10 +49,10 @@
if(widget.addEventListener) {
widget.addEventListener('keydown', checkKey, true);
-
widget.addEventListener('keyup', timer_change, false);
widget.addEventListener('blur', hideBox, false);
} else {
@@ -180,6 +182,12 @@
}
}
+function timer_change(e, value)
+{
- if (ajax_select_timer_id != 0) clearTimeout(ajax_select_timer_id);
- ajax_select_timer_id = setTimeout(function () { change(e, value); },
ajax_select_timeout);
+}
-
function change(e, value) {
if(!e) {
var e = window.event;
–
Raphael Alla
Alphalog Calédonie
Mitija Australia
+61 4 15 678 576
+687 78 86 86
http://www.mitija.com
http://www.alphalog.nc