/** * Returns the SELECT in HTML * * @access public * @return string */ function toHtml() { //print_r($this->_values); $this->updateAttributes(array('multiple' => 'multiple')); if ($this->_flagFrozen) { return $this->getFrozenHtml(); } else { $tabs = $this->_getTabs(); $strHtml = ''; if ($this->getComment() != '') { $strHtml .= $tabs . '<!-- ' . $this->getComment() . " //-->\n"; } $myName = $this->getName(); $this->updateAttributes(array('id' => $myName)); // Workaround for not processing attributes arg properly load_js('modules/Libs/QuickForm/FieldTypes/automulti/automulti.js'); $searchElement = ''; $search = new HTML_QuickForm_autocomplete($myName . '__search', '', array('HTML_QuickForm_automulti', 'get_autocomplete_suggestbox'), array($this->_options_callback, $this->_options_callback_args, $this->_format_callback)); $search->setAttribute('placeholder', __('Start typing to search...')); $search->on_hide_js('if($("__autocomplete_id_' . $myName . '__search").value!=""){automulti_on_hide("' . $myName . '","' . $this->list_sep . '");' . $this->on_add_js_code . '}'); $searchElement .= $tabs . $search->toHtml() . "\n"; if (isset($this->_values[0]) && (preg_match('/' . addcslashes($this->list_sep, '/') . '/i', $this->_values[0]) || $this->_values[0] == '')) { $this->_values = explode($this->list_sep, $this->_values[0]); array_shift($this->_values); } $this->setName($myName . '__display'); $mainElement = ''; $list = ''; $attrString = $this->_getAttrString($this->_attributes); $mainElement .= $tabs . '<select' . $attrString . ' onclick="automulti_remove_button_update(\'' . $myName . '\');">' . "\n"; if ($this->_format_callback) { foreach ($this->_values as $value) { $mainElement .= $tabs . "\t" . '<option value="' . $value . '">' . call_user_func($this->_format_callback, $value, $this->_options_callback_args) . '</option>' . "\n"; $list .= '__SEP__' . $value; } } $mainElement .= $tabs . '</select>'; $strHtml .= $tabs . '<table class="automulti">'; $strHtml .= $tabs . '<tr>' . $tabs . '<td class="search-element">' . $searchElement . '</td>' . ($this->search_button ? $tabs . '<td class="search">' . $this->search_button . '</td>' : '<td></td>') . $tabs . '<td width="80px;" class="button disabled" id="automulti_button_style_' . $myName . '">' . '<input style="width:100%" type="button" onclick="automulti_remove_button_action(\'' . $myName . '\', \'' . $this->list_sep . '\');' . $this->on_remove_js_code . '" value="' . __('Remove') . '">' . '</td>' . '</tr>'; $strHtml .= $tabs . '<tr><td class="main-element" colspan="3">' . $mainElement . '</td></tr></table>'; $this->setName($myName); $strHtml .= $tabs . '<input type="hidden" name="' . $myName . '" value="' . $list . '" id="' . $myName . '__var_holder" />' . "\n"; return $strHtml; } }
function toHtml() { if ($this->_flagFrozen) { return $this->getFrozenHtml(); } else { $tabs = $this->_getTabs(); $strHtml = ''; if ($this->getComment() != '') { $strHtml .= $tabs . '<!-- ' . $this->getComment() . " //-->\n"; } $myName = $this->getName(); $this->updateAttributes(array('id' => $myName)); eval_js('Event.observe("' . $myName . '", "keydown", function(ev){autoselect_start_searching("' . $myName . '", ev.keyCode)});'); if (!$this->getMultiple()) { $attrString = $this->_getAttrString($this->_attributes); } else { $this->setName($myName . '[]'); $attrString = $this->_getAttrString($this->_attributes); $this->setName($myName); } $strHtml .= $tabs . '<select' . $attrString . ">\n"; $mode = Base_User_SettingsCommon::get('Libs_QuickForm', 'autoselect_mode'); $val = $this->getValue(); if (isset($val[0]) && $val[0] != '' && !isset($this->__options[$val[0]]) && $this->more_opts_format) { $label = call_user_func_array($this->more_opts_format, array($val[0], $this->more_opts_args)); if ($label !== null) { $this->addOption(strip_tags($label), $val[0]); } } $strValues = is_array($this->_values) ? array_map('strval', $this->_values) : array(); $hint = __('Start typing to search...'); $strHtml .= '<option value="">' . $hint . '</option>'; // eval_js('set_style_for_search_tip = function(el){if($(el).value=="__SEARCH_TIP__")$(el).className="autoselect_search_tip";else $(el).className=""}'); // eval_js('set_style_for_search_tip("'.$myName.'");'); // eval_js('Event.observe("'.$myName.'", "change", function (){set_style_for_search_tip("'.$myName.'");});'); foreach ($this->_options as $option) { if (!empty($strValues) && in_array($option['attr']['value'], $strValues, true)) { $option['attr']['selected'] = 'selected'; } $strHtml .= $tabs . "\t<option" . $this->_getAttrString($option['attr']) . '>' . $option['text'] . "</option>\n"; } $strHtml .= $tabs . '</select>'; $text_attrs = array('placeholder' => $hint); $search = new HTML_QuickForm_autocomplete($myName . '__search', '', array('HTML_QuickForm_autoselect', 'get_autocomplete_suggestbox'), array($this->more_opts_callback, $this->more_opts_args, $this->more_opts_format), $text_attrs); $search->on_hide_js('autoselect_on_hide("' . $myName . '",' . ($mode ? '1' : '0') . ');' . $this->on_hide_js_code); if ($mode == 0) { eval_js('Event.observe("' . $myName . '","change",function(){if($("' . $myName . '").value=="")autoselect_start_searching("' . $myName . '");});'); } if (isset($val[0]) && $val[0] != '') { $mode = 1; } return '<span id="__' . $myName . '_select_span"' . ($mode == 0 ? ' style="display:none;"' : '') . '>' . $strHtml . '</span>' . '<span id="__' . $myName . '_autocomplete_span"' . ($mode == 1 ? ' style="display:none;"' : '') . '>' . $search->toHtml() . '</span>'; } }