PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_QuickForm_SelectFilter » Bug #4566

Add short delay before applying filter

Details

Request #4566Add short delay before applying filter
Submitted2005-06-10 14:41 UTC
Fromstudio at peptolab dot com
StatusOpen
PackageHTML_QuickForm_SelectFilter
PHP VersionIrrelevant
OSAny
Roadmaps(Not assigned)

Comments

[2005-06-10 14:41 UTC] studio at peptolab dot com

Description:
------------
The filter function will slow down, naturally, when the select
element contains many hundreds or even thousands of elements.
This delay can force, for example, 5 long-ish delays for a 5
letter filter word, as the filter is applied for each
keystroke.

It would be great to add a default behaviour to allow a small
timer (300 - 400milliseconds) to delay the filter to allow
enough time to capture many user keystrokes before it is fully
applied.

Reproduce code:
---------------
I have modified the javascript code below (a hack to get it to work) that demonstrates the desired behaviour:-

...existing code...

<script type="text/javascript">
//<![CDATA[
// begin javascript for filtered select
var values = new Array();
var QF_SelectFilterObj, QF_SelectFilterValue, QF_SelectFilterTimeout, QF_SelectFilterMustStart;
var QF_SelectFilterCnt = 0;

function QF_SelectFilterTimeOut(str, list, muststart) {
QF_SelectFilterCnt++;
QF_SelectFilterObj = list;
QF_SelectFilterValue = str;
QF_SelectFilterMustStart = muststart;
QF_SelectFilterTimeout = setTimeout("QF_SelectFilter(QF_SelectFilterValue, QF_SelectFilterObj, QF_SelectFilterMustStart)",350);
}

function QF_SelectFilter(str, list, muststart) {
QF_SelectFilterCnt--;
if (QF_SelectFilterCnt) { return false; }
str = QF_SelectFilterValue.value;
if (!values[list.name]) {
// first use of this list, we store initial elements

...continue...

The 'QF_SelectFilterCnt' allows for all keystrokes to set and clear timeouts before proceeding to apply the filter. I think there's certainly a more graceful way to handle the timeout syntax, but you get the idea!

Expected result:
----------------
The above code snippet will implement a Javascript timer to
allow extra keystrokes before the buffer is applied.

It would be also in keeping with the flexibility of the class
to allow a 'setDelay' method to the Quickform object to tweak
the delay as required.