From 4d17306e3e10eb56164de2a8a6e2b301eb5e8e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=C4=9Bzslav=20Dvo=C5=99=C3=A1k?= Date: Thu, 23 May 2019 18:12:36 +0200 Subject: [PATCH] Default value setting fixed --- src/FlexiPeeHP/ui/RecordSelector.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/FlexiPeeHP/ui/RecordSelector.php b/src/FlexiPeeHP/ui/RecordSelector.php index b0be197..97bb575 100644 --- a/src/FlexiPeeHP/ui/RecordSelector.php +++ b/src/FlexiPeeHP/ui/RecordSelector.php @@ -15,17 +15,18 @@ */ class RecordSelector extends \Ease\Html\SelectTag { + use \Ease\ui\Selectizer; /** * Selectize.js based input * * @param string $name - * @param array $values + * @param string $value * @param \FlexiPeeHP\FlexiBeeRO $optionsEngine * @param array $properties */ - public function __construct($name, $values, $optionsEngine, + public function __construct($name, $value, $optionsEngine, $properties = array()) { if (empty($optionsEngine->getColumnInfo('nazev'))) { @@ -40,14 +41,16 @@ public function __construct($name, $values, $optionsEngine, $keyColumn = 'kod'; } - parent::__construct($name, $values, $properties); - $values = $optionsEngine->getColumnsFromFlexibee([$keyColumn, $nameColumn]); - if ($keyColumn == 'kod') { - foreach ($values as $id => $valueRow) { - $values[$id][$nameColumn] = $values[$id][$keyColumn].': '.$values[$id][$nameColumn]; - } + $values = $optionsEngine->getColumnsFromFlexibee([$keyColumn, $nameColumn]); + $options = []; + + foreach ($values as $id => $valuesRow) { + $options[$values[$id][$keyColumn]] = $values[$id][$nameColumn]; } - - $this->selectize( ['valueField' => $keyColumn, 'labelField' => $nameColumn, 'searchField' => ['kod', 'nazev'], 'create' => false ],$values ); + + parent::__construct($name, $options, $value, [], $properties); + + $this->selectize(['valueField' => $keyColumn, 'labelField' => $nameColumn, + 'searchField' => ['kod', 'nazev'], 'create' => false]); } }