getAttribute('formatResult'); $formatCondition = null; if (!empty($formatResult)) { $formatCondition = ', templateResult : '.$formatResult.', templateSelection : '.$formatResult; } $width = 'element'; $givenWidth = '100%'; if (!empty($givenWidth)) { $width = $givenWidth; } //Get the minimumInputLength for select2 $minimumInputLength = $this->getAttribute('minimumInputLength') > 3 ? $this->getAttribute('minimumInputLength') : 3 ; $plHolder = $this->getAttribute('placeholder'); if (empty($plHolder)) { $plHolder = get_lang('SelectAnOption'); } $id = $this->getAttribute('id'); if (empty($id)) { $id = $this->getAttribute('name'); $this->setAttribute('id', $id); } $url = $this->getAttribute('url'); if (!$url) { $url = $this->getAttribute('url_function'); } else { $url = "'$url'"; } $html .= << $(function(){ $('#{$this->getAttribute('id')}').select2({ $languageCondition placeholder: '$plHolder', allowClear: true, width: '$width', minimumInputLength: '$minimumInputLength', ajax: { url: $url, dataType: 'json', data: function(params) { return { q: params.term, // search term page_limit: 10, }; }, processResults: function (data, page) { //parse the results into the format expected by Select2 return { results: data.items }; } $formatCondition } }); }); JS; $this->removeAttribute('formatResult'); $this->removeAttribute('minimumInputLength'); $this->removeAttribute('placeholder'); $this->removeAttribute('class'); $this->removeAttribute('url'); $this->removeAttribute('url_function'); $this->setAttribute('style', 'width: 100%;'); return parent::toHtml() . $html; } }