protected function _get_input_html(array $params = array())
 {
     $title = $this->_get_title();
     $attrs_html = self::_get_attr_html($params);
     $input_html = "<{$this->_tagname}{$attrs_html}>";
     if ($this->get_default_option_enabled()) {
         $option_text = $this->get_default_option_text() ? $this->get_default_option_text() : \ZPHP\String::get($this->get_optional() ? 'not_specified' : 'select');
         $input_html .= "<option value='" . \ZPHP\HTMLHelper::escape($this->get_default_option_value()) . "'>" . \ZPHP\HTMLHelper::escape($option_text) . "</option>";
         $input_html .= "<option value='" . \ZPHP\HTMLHelper::escape($this->get_default_option_value()) . "'></option>";
     }
     foreach ($this->_options as $option) {
         $option_tag = new HTMLLongTag('option', \ZPHP\HTMLHelper::escape($option['label']));
         $option_tag->set_param('value', \ZPHP\HTMLHelper::escape($option['value']));
         if (!is_null($this->get_value()) && $option['value'] == $this->get_value()) {
             $option_tag->set_param('selected', true);
         }
         $input_html .= $option_tag;
     }
     $input_html .= "</{$this->_tagname}>";
     $js_id = \ZPHP\JSHelper::cast_str('#' . $this->_get_id());
     $js_container_class = \ZPHP\JSHelper::cast_str(self::$_SELECT2_CONTAINER_CLASS);
     $js_searching = \ZPHP\String::get_js('searching');
     $js_no_matches = \ZPHP\String::get_js('no_matches_found');
     $js_placeholder = $this->_get_title();
     if ((!array_key_exists('placeholder', $params) || !$params['placeholder']) && $this->get_use_title_label() && $title) {
         $js_placeholder = $title;
     }
     $js_placeholder = \ZPHP\JSHelper::cast_str($js_placeholder);
     $input_html .= "<script type='text/javascript'>\n\n\t\t\t\t//\$(document).ready(function () {\n\t\t\t\t\t\t\$({$js_id}).select2({\n\t\t\tcontainerCssClass: {$js_container_class},\n\t\t\tformatSearching: function() {\n\t\t\treturn {$js_searching};\n\t\t\t},\n\t\t\tformatNoMatches: function() {\n\t\t\treturn {$js_no_matches};\n\t\t\t},";
     if ($this->get_width()) {
         $input_html .= "width: " . \ZPHP\JSHelper::cast_str($this->get_width()) . ",";
     }
     $input_html .= "dropdownAutoWidth: true,\n\t\t\tminimumResultsForSearch: -1,\n\t\t\tescapeMarkup: function(s) { return s; },\n\t\t\tplaceholder: {$js_placeholder}\n\t\t\t});";
     /*$(<?=JSHelper::cast_str("#{$id}")?><!--).on('change', function() { --><?//=$tag_attrs['onchange']?><!-- });-->*/
     //		$input_html.= " }); ";
     $input_html .= "\n</script>";
     return $input_html;
 }
 protected function _get_input_html(array $params = array())
 {
     $title = $this->_get_title();
     if ((!array_key_exists('placeholder', $params) || !$params['placeholder']) && $this->get_use_title_label() && $title) {
         $params['placeholder'] = $title;
     }
     $value = null;
     if (array_key_exists('value', $params)) {
         $value = self::parse_autocomplete_option($params['value']);
         if (!$value) {
             $value = array('id' => $params['value'], 'text' => '');
         }
         $params['value'] = $value['id'];
     }
     $attrs_html = self::_get_attr_html($params);
     $input_html = "<{$this->_tagname}{$attrs_html} />";
     $js_id = \ZPHP\JSHelper::cast_str('#' . $this->_get_id());
     $js_searching = \ZPHP\String::get_js('searching');
     $js_no_matches = \ZPHP\String::get_js('no_matches_found');
     $js_url = \ZPHP\JSHelper::cast_str($this->_request_url);
     $js_search_varname = \ZPHP\JSHelper::cast_str($this->_search_varname);
     $js_min_length = \ZPHP\JSHelper::cast_number($this->_min_length);
     $js_data = \ZPHP\JSHelper::cast_obj($this->_request_data);
     $js_method = \ZPHP\JSHelper::cast_str($this->_request_method);
     $js_placeholder = $this->_get_title();
     if ((!array_key_exists('placeholder', $params) || !$params['placeholder']) && $this->get_use_title_label() && $title) {
         $js_placeholder = $title;
     }
     $js_placeholder = \ZPHP\JSHelper::cast_str($js_placeholder);
     $js_window_id = \ZPHP\JSHelper::cast_str('#s2id_' . $this->_get_id());
     $html = "{$input_html}\n";
     $html .= "<script type='text/javascript'>\n";
     $html .= "if(!window[{$js_window_id}]) {\n\n\t\t\$({$js_id}).select2({formatSearching: function() {\n\t\t\treturn {$js_searching};\n\t\t\t},\n\t\t\tallowClear: " . JSHelper::cast_bool($this->_allow_clear) . ",\n\t\t\tformatNoMatches: function() {\n\t\t\treturn {$js_no_matches};\n\t\t\t},formatInputTooShort: function() {\n\t\t\t\treturn '';\n\t\t\t},\n\t\t\tescapeMarkup: function(s) { return s; },\n\t\t\tminimumInputLength: {$js_min_length},";
     if ($this->get_width()) {
         $html .= "width: " . \ZPHP\JSHelper::cast_str($this->get_width()) . ",";
     }
     $html .= "multiple: false,";
     if ($this->get_value()) {
         $html .= "placeholder: {$js_placeholder},";
     }
     $html .= "ajax: {\n\t\t\turl: {$js_url},\n\t\t\tdataType: 'json',\n\t\t\tdata: function(term, page)\n\t\t\t{\n\t\t\t\treturn \$.extend({}, { {$js_search_varname}: term}, {$js_data});\n\t\t\t},\n\t\t\tresults: function(data, page)\n\t\t\t{\n\t\t\t\treturn {results: data['rows']};\n\t\t\t}\n\t\t\t}\n\t\t";
     if ($value && is_array($value) && isset($value['id'])) {
         if (isset($value['text']) && $value['text']) {
             $html .= ", initSelection : function (element, callback) {\n\t\t\t\t\telement.val(" . \ZPHP\JSHelper::cast_str($value['id']) . ");\n\t\t\t\t\tcallback(" . \ZPHP\JSHelper::cast_obj($value) . ");\n\t\t\t\t}";
         } else {
             $html .= ", initSelection : function (element, callback) {\n\n\t\t\t\t\tvar ajaxData = {};\n\t\t\t\t\tajaxData[" . JSHelper::cast_str($this->_id_varname) . "] = " . JSHelper::cast_str($value['id']) . ";\n\n\t\t\t\t\t\$.ajax({\n\t\t\t\t\t\turl: {$js_url},\n\t\t\t\t\t\tdataType: 'json',\n\t\t\t\t\t\ttype: " . JSHelper::cast_str($this->_request_method) . ",\n\t\t\t\t\t\tdata: ajaxData,\n\t\t\t\t\t\tsuccess: function(data)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tvar row = null;\n\n\t\t\t\t\t\t\tif(data)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif(data['row'])\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\trow = data['row'];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if(data['rows'])\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\trow = data['rows'][0];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif(row)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\telement.val(row['id']);\n\t\t\t\t\t\t\t\tcallback(row);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}";
         }
     }
     $html .= "});";
     $html .= "window[{$js_window_id}] = true; }";
     $html .= "\n</script>";
     return $html;
 }