芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/.trash/cepali/lib/pear/HTML/QuickForm/autocomplete.php
| // | | // | 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$ 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 */ public function __construct($elementName = null, $elementLabel = null, $options = null, $attributes = null) { parent::__construct($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->_type = 'autocomplete'; if (isset($options)) { $this->setOptions($options); } } //end constructor /** * Old syntax of class constructor. Deprecated in PHP7. * * @deprecated since Moodle 3.1 */ public function HTML_QuickForm_autocomplete($elementName = null, $elementLabel = null, $options = null, $attributes = null) { debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER); self::__construct($elementName, $elementLabel, $options, $attributes); } // }}} // {{{ 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 ?>