* @copyright 2009-2011 WCE
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version v 0.1
*/
/**
* HTML class for a text field
*/
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/text.php';
/**
* We'll use the PHP_EOL constant
*
* @link http://pear.php.net/package/PHP_Compat
*/
if (!defined('PHP_EOL')) {
require_once 'PHP/Compat/Constant/PHP_EOL.php';
}
class HTML_QuickForm_autosuggestwce extends HTML_QuickForm_text
{
// {{{ properties
/**
* Options for the autosuggestwce input text element
*
* @var array
* @access private
*/
var $_config = array();
/**
* "One-time" javascript (containing functions), see bug #4611
*
* @var string
* @access private
*/
var $_js = '';
/**
* The URL where to find the javascript files
*
*
* @var string
* @access public
*/
var $basePath;
// }}}
// {{{ constructor
/**
* Class constructor
*
* @param string $elementName (optional)Input field name attribute
* @param string $elementLabel (optional)Input field label in form
* @param array $options (optional)Autocomplete options
* @param mixed $attributes (optional)Either a typical HTML attribute string
* or an associative array. Date format is passed along the attributes.
* @access public
* @return void
*/
function HTML_QuickForm_autosuggestwce($elementName = null, $elementLabel = null, $options = null, $attributes = null)
{
if(isset($attributes['fileref'])) {
$this->_config['fileref'] =$attributes['fileref'];
unset($attributes['fileref']);
}
$this->HTML_QuickForm_text($elementName, $elementLabel, $attributes);
$this->_persistantFreeze = true;
$this->_type = 'autosuggestwce';
} //end constructor
// {{{ toHtml()
/**
* Returns Html for the autosuggestwce input text element
*
* @access public
* @return string
*/
function toHtml()
{
if ($this->_flagFrozen) {
return $this->getFrozenHtml();
}
$name = $this->getAttribute('name');
$id = $this->getAttribute('id');
if (is_null($id)) {
$id = $name.'wcefield';
$this->updateAttributes(array('id' => $id));
}
$id = preg_replace('/[^a-zA-Z0-9-_]/', '___', $id);
$html = '';
$jscript = '';
$basePath = (empty($this->basePath))
? $GLOBALS['_HTML_QUICKFORM_AUTOSUGGEST_BASEPATH']
: $this->basePath;
if(!defined('HTML_QUICKFORM_AUTOSUGGEST_LOADED'))
{
$html = ''
.PHP_EOL
.''
.PHP_EOL
.''
.PHP_EOL;
define('HTML_QUICKFORM_AUTOSUGGEST_LOADED', true);
}
$this->updateAttributes(array('autocomplete' => 'off'));
$html .= parent::toHtml();
$jscript = 'new AutoComplete(\''.$id.'\', \''.$this->_config['fileref'].'?m=json&s=\', {'.PHP_EOL
.' delay: 0.25,'.PHP_EOL
.'resultFormat: AutoComplete.Options.RESULT_FORMAT_JSON '.PHP_EOL
.'});'.PHP_EOL;
$html .= PHP_EOL
.''.PHP_EOL;
return $html;
}
// }}}
/**
* Returns the autosuggestwce content in HTML
*
* @return string
* @access public
*/
function getFrozenHtml()
{
$value = $this->getValue();
return implode('
'.PHP_EOL, $value);
}
} // end class HTML_QuickForm_autosuggestwce
/**
* Register the element
*/
HTML_QuickForm::registerElementType('autosuggestwce',
'HTML/QuickForm/wceautosuggest.php',
'HTML_QuickForm_autosuggestwce');
?>