class Eve_Form_Element_TextboxList extends Zend_Form_Element_Xhtml { /** * * @var string */ public $helper = 'formTextboxList'; /** * - * @var array */ public $options = array( 'js_main' => '/js/jquery.textboxlist.js', // 'js_autocomplete' => '/js/jquery.textboxlist.autocomplete.js', // ( ) 'js_growinginput' => '/js/jquery.growinginput.js', // 'use_autocompletion' => '0', // 'autocomplete_script' => null, // backend, 'css_main' => '/css/textboxlist.css', // 'css_autocomplete' => '/css/textboxlist.autocomplete.css', ); /** * * * @param array $options * @return Eve_Form_Element_TextboxList */ public function setOptions(array $options) { /** * , , * */ $diff = array_intersect_key($options, $this->options); $this->options = array_merge($this->options, $diff); /** * , html */ foreach ($diff as $key => $option) { unset ($options[$key]); } parent::setOptions($options); return $this; } }
class Eve_View_Helper_FormTextboxList extends Zend_View_Helper_FormElement { /** * Generates a 'textboxList' element. * * @access public * * @param string|array $name If a string, the element name. If an * array, all other parameters are ignored, and the array elements * are extracted in place of added parameters. * * @param mixed $value The element value. * * @param array $attribs Attributes for the element tag. * * @return string The element XHTML. */ public function formTextboxList($name, $value = '', $attribs = null, $options = null) { $id = $name; $elemId = $this->view->escape($id); $xhtml = '<input type="text" name="' . $this->view->escape($name) . '" id="' . $this->view->escape($id) . '"'; // if (!empty($value)) { $xhtml .= ' value="' . $this->view->escape($value) . '"'; } // html $xhtml .= $this->_htmlAttribs($attribs); $xhtml .= '/>' . PHP_EOL; /** * , , .. , * , . */ // add content and end tag $xhtml .= $content . ($this->view->doctype()->isXhtml() ? '/>' : '>') . PHP_EOL; $this->view->headScript->appendFile($options['js_growinginput']); $this->view->headScript->appendFile($options['js_main']); $this->view->headScript->appendFile($options['js_autocomplete']); $this->view->headLink->appendStylesheet($options['css_main']); $this->view->headLink->appendStylesheet($options['css_autocomplete']); $xhtml .= '<script type="text/javascript"> var tl_' . $elemId . ' = new $.TextboxList("#' . $elemId. '", {unique: true, plugins: {autocomplete: {}}}); '; if ((int) $options['use_autocompletion'] == 1) { if (!$options['autocomplete_script']) { throw new Zend_View_Exception('No autocompletion backend is set for ' . __CLASS__ . ' plugin.'); } else { $.getJSON('" . $options['autocomplete_script'] . "', null, function (data) { tl.plugins['autocomplete'].setValues(data); tl.getContainer().removeClass('textboxlist-loading'); });"; } } $xhtml .= '</script>'; return $xhtml; } }
elements.categories.type = textboxList elements.categories.options.label = Categories elements.categories.options.use_autocompletion = 1 elements.categories.options.autocomplete_script = /categories/ajax/get-all/
Source: https://habr.com/ru/post/126133/