Source for file livesearch_select.php
Documentation is available at livesearch_select.php
/* vim: set number autoindent tabstop=2 shiftwidth=2 softtabstop=2: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.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/3_0.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. |
// +----------------------------------------------------------------------+
// | Author: Giuseppe Dessì <thesee@fastwebnet.it> |
// +----------------------------------------------------------------------+
* Class to dynamically create an HTML input text element that
* at every keypressed javascript event, call by XMLHttpRequest for sending
* the request to the server. A PHP script or XML or a static file returns
* a response in a arbitrary format, depending on the our needed.
* We can see the data on a live dropdown select
* @author Giuseppe Dessì <thesee@fastwebnet.it>
require_once 'HTML/QuickForm/text.php';
class HTML_QuickForm_LiveSearch_Select extends HTML_QuickForm_text
* Options for the LiveSearch_Select input text element
* Original name of element
* The values passed by the hidden element
var $_hidden_value = null;
* @param string $elementName (required)Input field name attribute
* @param string $elementLabel (required)Input field label in form
* @param array $options (optional)LiveSearch_Select options
* @param mixed $attributes (optional)Either a typical HTML attribute string
* or an associative array. Date format is passed along the attributes.
function HTML_QuickForm_LiveSearch_Select ($elementName = null , $elementLabel = null , $options = null , $attributes = null )
$this->HTML_QuickForm_text ($elementName, $elementLabel, $attributes);
$this->_persistantFreeze = true;
$this->_type = 'livesearch_select';
$this->setOptions ($options);
* Gets the private name for the element
* @param string $elementName The element name to make private
function getPrivateName ($elementName)
* Sets the element's value
* @param mixed Element's value
function setValue ($value)
$this->_hidden_value = $value;
if (isset ($this->_options['callback']) AND is_callable($this->_options['callback']) ) {
if (isset ($this->_options['dbh']) ) {
$dbh = $this->_options['dbh'];
$this->_value = call_user_func($this->_options['callback'], $dbh, $value);
$this->updateAttributes (array (
$this->updateAttributes (array (
* Gets the element's value
* @param mixed Element's value
function getValue ($internal = NULL )
if ($this->_flagFrozen) {
return $this->_hidden_value;
return $this->_hidden_value;
* Sets the options for the LiveSearch_Select input text element
* @param array $options Array of options for the LiveSearch_Select input text element
function setOptions ($options)
$this->_options = $options;
* Returns the value of field without HTML tags
$value = $this->getValue (true );
$id = $this->getAttribute ('id');
return ('' != $value ? htmlspecialchars($value): ' '). '<input' . $this->_getAttrString (array (
'name' => $this->realName,
'value' => $this->getValue ()
) + (isset ($id)? array ('id' => $id): array ())) . ' />';
} //end func getFrozenHtml
* Returns Html for the LiveSearch_Select input text element
$this->realName = $this->getName ();
$style = 'display: block;';
$divstyle = ' class="divstyle" ';
$ulstyle = ' class="ulstyle" ';
$listyle = ' class="listyle" ';
$this->updateAttributes (array (
'name' => $this->getPrivateName ($this->realName)
if (isset ($this->_options['style']) AND $this->_options['style'] != '') {
$style = $this->_options['style'];
if (isset ($this->_options['divstyle']) AND $this->_options['divstyle'] != '') {
$divstyle = ' class="'. $this->_options['divstyle']. '" ';
if (isset ($this->_options['ulstyle']) AND $this->_options['ulstyle'] != '') {
$ulstyle = ' class="'. $this->_options['ulstyle']. '" ';
if (isset ($this->_options['listyle']) AND $this->_options['listyle'] != '') {
$listyle = ' class="'. $this->_options['listyle']. '" ';
if (isset ($this->_options['searchZeroLength']) AND $this->_options['searchZeroLength'] == 1 ) {
if (isset ($this->_options['printStyle']) AND $this->_options['printStyle'] != 1 ) {
if (isset ($this->_options['autoserverPath']) AND $this->_options['autoserverPath'] != '') {
$autoserverPath = $this->_options['autoserverPath'];
if (isset ($this->_options['autoComplete']) AND $this->_options['autoComplete'] != 0 ) {
$this->updateAttributes (array (
$this->updateAttributes (array (
'onkeyup' => 'javascript:liveSearchKeyPress(this, event, \''. $this->getName (). 'Result\', \'target_'. $this->_options['elementId']. '\', \''. $this->_options['elementId']. '\', \''. $this->realName. '\', '. $zeroLength. ');',//'javascript:'.$this->getName().'ObjLS.liveSearchKeyPress(this, event);disable();',
'onblur' => 'javascript:liveSearchHide(\''. $this->getName (). 'Result\');',
'id' => $this->_options['elementId'],
if ($this->_flagFrozen) {
return $this->getFrozenHtml ();
<div'. $divstyle. 'id="'. $this->getName (). 'Result">
<ul'. $ulstyle. 'id="target_'. $this->_options['elementId']. '">
<li'. $listyle. '> </li>
if (!defined('HTML_QUICKFORM_LIVESEARCH_EXISTS')) {
background: url(shadowAlpha.png) no-repeat bottom right !important;
background: url(shadow.gif) no-repeat bottom right;
margin: 10px 0 10px 10px !important;
* html .divstyle { width: 140px;}
background-color: #FFFFFF;
border: 1px solid #999999;
padding: 2px 15px 2px 20px;
<script type='text/javascript' src="{ $autoserverPath}auto_server.php?client=Util,main,dispatcher,httpclient,request,json,loading,queues,QfLiveSearch&stub=livesearch"></script>
<script type='text/javascript'>//<![CDATA[
function searchRequest(searchBox, callfunc) {
eval("remoteLiveSearch."+callfunc+"(searchBox.value)");
define('HTML_QUICKFORM_LIVESEARCH_EXISTS', true );
<script type="text/javascript">//<![CDATA[
callback.'. $this->_options['elementId']. ' = function(result) {
var res = document.getElementById(\''. $this->getName (). 'Result\');
res.style.display = "block";
var out = "<ul class=\"outerUl\" >";
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>";
document.getElementById(\'target_'. $this->_options['elementId']. '\').innerHTML = out;
if (!defined('HTML_QUICKFORM_JS_INIT_EXISTS')) {
<script type="text/javascript">//<![CDATA[
var remoteLiveSearch = new livesearch(callback);
remoteLiveSearch.dispatcher.queue = \'rls\';
HTML_AJAX.queues[\'rls\'] = new HTML_AJAX_Queue_Interval_SingleBuffer('.(int) $this->_options['buffer']. ');
define('HTML_QUICKFORM_JS_INIT_EXISTS', true );
<input type="hidden" name="'. $this->realName. '" id="'. $this->realName. '" value="'. $this->_hidden_value. '" />'. "\n";
return $scriptLoad.parent ::toHtml (). $liveform;
} // end class HTML_QuickForm_LiveSearch_Select
HTML_QuickForm ::registerElementType ('livesearch_select', 'HTML/QuickForm/livesearch_select.php', 'HTML_QuickForm_LiveSearch_Select');
Documentation generated on Mon, 11 Mar 2019 15:48:25 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|