_options) { $this->_options = Qs_Array::excludeKey($this->getElement()->getAttribs(), 'helper', 'options', 'class'); } return $this->_options; } public function setOptions(array $options) { if (isset($options['options'])) { unset($options['options']); } foreach ($options as $key => $value) { $method = 'set' . ucfirst($key); if (method_exists($this, $method)) { $this->$method($value); } else { $this->_options[$key] = $value; } } return $this; } public function initRender() { /** @var $doc Qs_Doc */ $doc = Zend_Registry::get('doc'); $doc->addScript('js/jquery-ui.js') ->addScript('js/jquery.bgiframe.js') ->addScript('js/lib/form-element-autocomplete.js'); $doc->addInitObject('Qs_Form_Element_Autocomplete', array($this->_getScriptOptions())); // "jquery-ui.css" removed to fix styles return $this; } public function render($content) { // init options $this->getOptions(); $tag = $this->getTag(); $element = $this->getElement(); $id = $element->getId(); $_id = $element->getDisplayId(); $__id = $element->getTitleId(); $view = $element->getView(); $placement = $this->getPlacement(); $separator = $this->getSeparator(); $value = $element->getValue(); $_value = $element->getTitle(); $__value = $_value; // the values are same for title and display fields $name = $element->getFullyQualifiedName(); $_name = $element->getFullyQualifiedDisplayName(); $__name = $element->getFullyQualifiedTitleName(); $elementContent = $view->formHidden($name, $value, array('id' => $id)); // The element below required for validation $attribs = $this->getElementAttribs(); $attribs['id'] = $_id; $elementContent .= $view->formText($_name, $_value, $attribs); $elementContent .= $view->formHidden($__name, $__value, array('id' => $__id)); switch ($placement) { case self::PREPEND: return $elementContent . $separator . $content; case self::APPEND: // break intentionally omitted default: return $content . $separator . $elementContent; } } public function getElementAttribs() { if (null === ($element = $this->getElement())) { return null; } $attribs = Qs_Array::excludeKey($this->getElement()->getAttribs(), 'helper', 'options'); if (isset($attribs['id'])) { return $attribs; } $id = $element->getName(); if ($element instanceof Zend_Form_Element) { if (null !== ($belongsTo = $element->getBelongsTo())) { $belongsTo = preg_replace('/\[([^\]]+)\]/', '-$1', $belongsTo); $id = $belongsTo . '-' . $id; } } $element->setAttrib('id', $id); $attribs['id'] = $id; return $attribs; } protected function _getScriptOptions() { $options = (array) $this->getOptions(); $element = $this->getElement(); if (($tmp = $element->getDataUrl())) { $options['dataUrl'] = $tmp; } elseif (($tmp = $element->getDataCallback())) { $options['dataCallback'] = $tmp; } elseif (($tmp = $element->getDataArray())) { $options['dataArray'] = $tmp; } else { $tmp = $this->getElement()->getMultiOptions(); $options['dataArray'] = array(); foreach ($tmp as $value => $title) { $options['dataArray'][] = array('value' => $value, 'title' => $title); } } $options['valueElementId'] = $element->getId(); $options['displayElementId'] = $element->getDisplayId(); $options['titleElementId'] = $element->getTitleId(); return $options; } }