| // | | // | For the JavaScript code thanks to Martin Honnen and | // | Nicholas C. Zakas | // | See: | // | http://www.faqts.com/knowledge_base/view.phtml/aid/13562 | // | and | // | http://www.sitepoint.com/article/1220 | // +----------------------------------------------------------------------+ // // $Id: autocomplete.php,v 1.1 2006/09/24 17:04:54 jamiesensei Exp $ require_once("HTML/QuickForm/text.php"); /** * Class to dynamically create an HTML input text element that * at every keypressed javascript event, check in an array of options * if there's a match and autocomplete the text in case of match. * * Ex: * $autocomplete =& $form->addElement('autocomplete', 'fruit', 'Favourite fruit:'); * $options = array("Apple", "Orange", "Pear", "Strawberry"); * $autocomplete->setOptions($options); * * @author Matteo Di Giovinazzo */ class HTML_QuickForm_autocomplete extends HTML_QuickForm_text { // {{{ properties /** * Options for the autocomplete input text element * * @var array * @access private */ var $_options = array(); /** * "One-time" javascript (containing functions), see bug #4611 * * @var string * @access private */ var $_js = ''; // }}} // {{{ 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_autocomplete($elementName = null, $elementLabel = null, $options = null, $attributes = null) { $this->HTML_QuickForm_text($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->_type = 'autocomplete'; if (isset($options)) { $this->setOptions($options); } } //end constructor // }}} // {{{ setOptions() /** * Sets the options for the autocomplete input text element * * @param array $options Array of options for the autocomplete input text element * @access public * @return void */ function setOptions($options) { $this->_options = array_values($options); } // end func setOptions // }}} // {{{ toHtml() /** * Returns Html for the autocomplete input text element * * @access public * @return string */ function toHtml() { // prevent problems with grouped elements $arrayName = str_replace(array('[', ']'), array('__', ''), $this->getName()) . '_values'; $this->updateAttributes(array( 'onkeypress' => 'return autocomplete(this, event, ' . $arrayName . ');' )); if ($this->_flagFrozen) { $js = ''; } else { $js = ""; } return $js . parent::toHtml(); }// end func toHtml // }}} } // end class HTML_QuickForm_autocomplete ?>