Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #596 (closed defect: fixed)

Opened 13 years ago

Last modified 12 years ago

[PATCH] Avoid spamming JSON requests in AutoCompleteField

Reported by: bjourne Owned by: anonymous
Priority: normal Milestone:
Component: TG Widgets Version:
Severity: normal Keywords:


When you type a string like "turbogears" into an AutoCompleteField, the Javascript will send a JSON request to the web server for each character typed. First "t" then "tu", "tur", "turb", "turbo", "turbog" and so on. This behaviour is very wasteful and leads to the AutoCompleteField becoming less responsive if the web server request takes time and if you type quickly. You will see completions for to old strings. For example, the field will display completions for "turb" but you have already managed to type "turbogears".

This patch changes the AutoCompleteField's behaviour by modifying autocompletefield.js. When a key is pressed a 150 millisecond timer is started. It is assumed that if the user types another character within those 150 milliseconds they don't need a completion yet and the timer is restarted. Only when the timer times out (i.e: the user pauses for more than 150 milliseconds) is the JSON request sent. The patch implements this by breaking out code from theKeyUp() method into two new methods: doDelayedRequest() (called when the timer times out) and displayResults() (called when the JSON request returns data).


acfield-delay-result-fetching.patch Download (8.6 KB) - added by bjourne 13 years ago.
Patch for this ticket :)

Change History

comment:1 Changed 13 years ago by roger.demetrescu

Hi bjourne,

I'm almost sure you've forgotten do attach the patch. :)

Thanks anyway...

Changed 13 years ago by bjourne

Patch for this ticket :)

comment:2 Changed 13 years ago by kevin

  • Status changed from new to closed
  • Resolution set to fixed

Committed in [831]. Thanks!

Note: See TracTickets for help on using tickets.