From 7b68d8fc36d5b75ce5fee8ee756d727dabaa1b94 Mon Sep 17 00:00:00 2001 From: Michele Rota Date: Fri, 1 Jul 2016 18:06:30 +0200 Subject: [PATCH] This MultiSelectListAttribute and ListAttribute --- src/Attributes/ListAttribute.php | 1 - src/Attributes/MultiSelectListAttribute.php | 27 ++++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Attributes/ListAttribute.php b/src/Attributes/ListAttribute.php index f75af43b3..8a59e7d9f 100644 --- a/src/Attributes/ListAttribute.php +++ b/src/Attributes/ListAttribute.php @@ -277,7 +277,6 @@ public function edit($record, $fieldprefix, $mode) $this->getOwnerInstance()->getPage()->register_loadscript('jQuery("#'.$id.'").select2();'); $selectOptions = []; - $onchange = ''; if (count($this->m_onchangecode)) { $onchange = ' onChange="'.$this->getHtmlId($fieldprefix).'_onChange(this)"'; diff --git a/src/Attributes/MultiSelectListAttribute.php b/src/Attributes/MultiSelectListAttribute.php index 11e556b4f..201b68e11 100644 --- a/src/Attributes/MultiSelectListAttribute.php +++ b/src/Attributes/MultiSelectListAttribute.php @@ -9,7 +9,7 @@ class MultiSelectListAttribute extends ListAttribute { const AF_NO_TOGGLELINKS = 536870912; - + /** * Default field separator. * @@ -144,16 +144,28 @@ public function edit($record, $fieldprefix, $mode) { $id = $this->getHtmlId($fieldprefix); $name = $this->getHtmlName($fieldprefix); + $this->getOwnerInstance()->getPage()->register_loadscript('jQuery("#'.$id.'").select2();'); $selectOptions = []; + $selectOptions['dropdown-auto-width'] = true; + $selectOptions['minimum-results-for-search'] = 10; + $selectOptions['tags'] = true; + if ($this->m_width) { + $selectOptions['width'] = $this->m_width; + } + + $data = ''; + foreach ($selectOptions as $k => $v) { + $data .= ' data-'.$k.'="'.htmlspecialchars($v).'"'; + } $onchange = ''; if (count($this->m_onchangecode)) { - $onchange = $id.'_onChange(this);'; + $onchange = ' onChange="'.$this->getHtmlId($fieldprefix).'_onChange(this)"'; $this->_renderChangeHandler($fieldprefix); } - $result = 'getCSSClassAttribute('form-control').'" '.$onchange.$data.'>'; $values = $this->getValues(); if (!is_array($record[$this->fieldName()])) { @@ -171,15 +183,6 @@ public function edit($record, $fieldprefix, $mode) $result .= ''; - $selectOptions['tags'] = true; - $selectOptions['width'] = '100%'; - - $script = "jQuery('#$id').select2(".json_encode($selectOptions).")"; - if ($onchange != '') { - $script .= '.on("change", function(){'.$onchange.'})'; - } - $result .= ''; - return $result; }