Source for file SelectFilter.php
Documentation is available at SelectFilter.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Nicolas Hoizey <nicolas@hoizey.com> |
// +----------------------------------------------------------------------+
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/text.php';
* Class to dynamically create a filter for an HTML SELECT
* @author Nicolas Hoizey <nicolas@hoizey.com>
class HTML_QuickForm_SelectFilter extends HTML_QuickForm_text {
* Contains the select targets
* @param string $elementName (optional)Input field name attribute
* @param string $elementLabel (optional)Input field label
* @param mixed $attributes (optional)Either a typical HTML attribute string
* or an associative array
* @param string $selectName (optional)Target select field name
* @param boolean $mustBeginWith (optional)Indicates wether the select
* must begin with the filtered value or
function HTML_QuickForm_SelectFilter ($elementName = null , $elementLabel = null , $attributes = null , $selectName = null , $mustBeginWith = false )
$this->HTML_QuickForm_text ($elementName, $elementLabel, $attributes);
$this->_type = 'selectfilter';
$this->addSelect ($selectName, $mustBeginWith);
* Adds a select as a target of the filter
* @param string $selectName Target select field name
* @param boolean $mustBeginWith (optional)Indicates wether the select
* must begin with the filtered value or
function addSelect ($selectName, $mustBeginWith = false )
$this->_targets[$selectName] = $mustBeginWith;
* Returns the current API version
* Returns the filter in HTML
foreach($this->_targets as $target => $mustBeginWith) {
$onKeyUp .= 'javascript:QF_SelectFilter(this.value, this.form[\''. $target. '\'], '. ($mustBeginWith ? 'true' : 'false'). ');';
$this->updateAttributes (array ('onkeyup' => $onKeyUp));
if ($this->_flagFrozen) {
return $this->getFrozenHtml ();
$tabs = $this->_getTabs ();
if (count($this->_targets) > 0 && !defined('HTML_QUICKFORM_SELECTFILTER_EXISTS')) {
<script type="text/javascript">
// begin javascript for filtered select
var values = new Array();
function QF_SelectFilter(str, list, muststart) {
if (!values[list.name]) {
// first use of this list, we store initial elements
nb = list.options.length;
values[list.name] = new Array(nb);
for (i = 0; i < nb; i++) {
values[list.name][i] = list.options[i];
for(i = list.options.length - 1; i >= 0; i--) {
for (i = 0; i < nb; i++) {
|| (muststart && values[list.name][i].text.toUpperCase().indexOf(str.toUpperCase()) == 0)
|| (!muststart && values[list.name][i].text.toUpperCase().indexOf(str.toUpperCase()) != -1)) {
list.options[index] = new Option(values[list.name][i].text, values[list.name][i].value);
list.options[0].selected = true;
// end javascript for filtered select
define('HTML_QUICKFORM_SELECTFILTER_EXISTS', true );
return $js . parent ::toHtml ();
} //end class HTML_QuickForm_SelectFilter
HTML_QuickForm ::registerElementType ('SelectFilter', 'HTML/QuickForm/SelectFilter.php', 'HTML_QuickForm_SelectFilter');
Documentation generated on Mon, 11 Mar 2019 13:59:55 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|