From b6a8d5e8afe89396646c97d383a57590a77b3757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Z=C3=A1le=C5=A1=C3=A1k?= Date: Tue, 26 Oct 2021 12:56:52 +0200 Subject: [PATCH 01/20] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index ebcc0c7..8a2fe31 100644 --- a/README.md +++ b/README.md @@ -418,3 +418,8 @@ public function init($form) { ``` +## ToDo + +### orById filtr pro zanořené selecty + +Pokud máme select uvnitř toMany nebo addDynamic, tak musí být nastaveno `AjaxSelectExtension::CONFIG_OR_BY_ID_FILTER => FALSE`, aby se knihovna nepokoušela přistoupit k atributu dle názvu selectu v hlavní entitě, což by skončilo chybou. Toto rozšíření orById filtru pro zanořené selecty by se dalo naimplementovat, že bychom si v kontejneru selectu zjistili, kam je select zanořený (může být víc než jedna úroveň zanoření) a podle toho bychom místo `$form->getEntity()->get{$atributeName}()` provolali všechny prvky zanoření, tedy `$form->getEntity()->get{$zanořenýPrvek}($indexPrvku)->...->get{$atributeName}()` From 0966649ea2867683ed0832fb4fc1e14504a6c2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Z=C3=A1le=C5=A1=C3=A1k?= Date: Tue, 16 Nov 2021 16:55:10 +0100 Subject: [PATCH 02/20] Translator switch Option to turn off automatic translation of select values --- README.md | 3 +++ .../AjaxSelect/DI/AjaxSelectExtension.php | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8a2fe31..9781785 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,12 @@ This extension adds following methods to `Nette\Forms\Container` and thus to all [ AjaxSelectExtension::CONFIG_INVALID_VALUE_MODE => AjaxSelectExtension::INVALID_VALUE_MODE_*, AjaxSelectExtension::CONFIG_OR_BY_ID_FILTER => TRUE, + AjaxSelectExtension::CONFIG_TRANSLATOR => TRUE, ] ``` +`AjaxSelectExtension::CONFIG_TRANSLATOR`: Sets the automatic translation of select values on/off. Default is `TRUE`. + ### Dynamic Select This control allows passing unknown value to `$control->value` field. Doing so will invoke control's `$itemFactory` with only one parameter - the invalid value. diff --git a/src/Components/AjaxSelect/DI/AjaxSelectExtension.php b/src/Components/AjaxSelect/DI/AjaxSelectExtension.php index f2f424e..e625e63 100644 --- a/src/Components/AjaxSelect/DI/AjaxSelectExtension.php +++ b/src/Components/AjaxSelect/DI/AjaxSelectExtension.php @@ -18,6 +18,8 @@ class AjaxSelectExtension extends \Nette\DI\CompilerExtension { const CONFIG_OR_BY_ID_FILTER = 'orByIdFilter'; + const CONFIG_TRANSLATOR = 'translator'; + const ENTITY_FACTORY_TAG = 'ajax-select.entity-factory'; public function loadConfiguration() { @@ -25,6 +27,7 @@ public function loadConfiguration() { static::CONFIG_GET_ITEMS_SIGNAL_NAME => 'getAjaxItems', static::CONFIG_INVALID_VALUE_MODE => static::INVALID_VALUE_MODE_EXCEPTION, static::CONFIG_OR_BY_ID_FILTER => TRUE, + static::CONFIG_TRANSLATOR => TRUE, ]; $builder = $this->getContainerBuilder(); @@ -125,11 +128,16 @@ public static function register(\Nette\DI\Container $container, $globalConfig) { /** @var AjaxSelect\AjaxSelect|AjaxSelect\DynamicSelect|mixed $control */ $control = new $class($label); - $config = static::processConfigOptions($config, $globalConfig, [static::CONFIG_INVALID_VALUE_MODE, static::CONFIG_OR_BY_ID_FILTER]); + $config = static::processConfigOptions($config, $globalConfig, [static::CONFIG_INVALID_VALUE_MODE, static::CONFIG_OR_BY_ID_FILTER, static::CONFIG_TRANSLATOR]); // set invalid value mode $control->setInvalidValueMode($config[static::CONFIG_INVALID_VALUE_MODE]); + // set translator + if (!$config[static::CONFIG_TRANSLATOR]) { + $control->setTranslator(NULL); + } + // inject ajax entity /** @var AjaxSelect\Services\AjaxService $ajaxService */ $ajaxService = $serviceGetter(); @@ -148,7 +156,7 @@ public static function register(\Nette\DI\Container $container, $globalConfig) { // pro dymanic select return function (\Nette\Forms\Container $container, $name, $label = NULL, $items = NULL, $itemFactory = NULL, $config = []) use ($class, $serviceGetter, $globalConfig) { - $config = static::processConfigOptions($config, $globalConfig, [static::CONFIG_INVALID_VALUE_MODE, static::CONFIG_OR_BY_ID_FILTER]); + $config = static::processConfigOptions($config, $globalConfig, [static::CONFIG_INVALID_VALUE_MODE, static::CONFIG_OR_BY_ID_FILTER, static::CONFIG_TRANSLATOR]); // if $items are not array of values, we have received query object if ($items instanceof \ADT\BaseQuery\BaseQuery) { @@ -168,6 +176,11 @@ public static function register(\Nette\DI\Container $container, $globalConfig) { // set invalid value mode $control->setInvalidValueMode($config[static::CONFIG_INVALID_VALUE_MODE]); + // set translator + if (!$config[static::CONFIG_TRANSLATOR]) { + $control->setTranslator(NULL); + } + $control->setItemFactory($itemFactory); return $container[$name] = $control; From 1bc7433a824dfc195c1f3ae4ef0197eb126e51c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 28 May 2023 06:35:00 +0200 Subject: [PATCH 03/20] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 396505c..819a125 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "php": ">=7.1", "nette/forms": "^3.0", "nette/di": "^3.0", - "nette/utils": "^3.0", + "nette/utils": "^3.0 | ^4.0", "nette/application": "*", "adt/base-query": "^1.7" }, From d6afcfe97dc8af0bbc7d4234345df51cd8bde435 Mon Sep 17 00:00:00 2001 From: vpalousek98 <45952170+vpalousek98@users.noreply.github.com> Date: Fri, 19 Apr 2024 15:25:17 +0200 Subject: [PATCH 04/20] Update AbstractEntity.php fix --- src/Components/AjaxSelect/Entities/AbstractEntity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index c6ac2a0..f189e99 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -10,7 +10,7 @@ abstract class AbstractEntity { use SmartObject; - const DATA_ATTRIBUTE_NAME = 'data-ajax-select'; + const DATA_ATTRIBUTE_NAME = 'data-adt-ajax-select'; const OPTION_QUERY = 'q'; From 766fa1667072105e0d6b6b52fb523382d2fb7b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 14 Jul 2024 08:43:29 +0200 Subject: [PATCH 05/20] Calling static trait method is deprecated --- .../AjaxSelect/DI/AjaxSelectExtension.php | 4 +++- .../AjaxSelect/Entities/AbstractEntity.php | 4 +++- .../Interfaces/OrByIdFilterInterface.php | 9 +++++++++ .../AjaxSelect/Traits/OrByIdFilterTrait.php | 15 +++++---------- 4 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 src/Components/AjaxSelect/Interfaces/OrByIdFilterInterface.php diff --git a/src/Components/AjaxSelect/DI/AjaxSelectExtension.php b/src/Components/AjaxSelect/DI/AjaxSelectExtension.php index e625e63..449ceb4 100644 --- a/src/Components/AjaxSelect/DI/AjaxSelectExtension.php +++ b/src/Components/AjaxSelect/DI/AjaxSelectExtension.php @@ -160,7 +160,9 @@ public static function register(\Nette\DI\Container $container, $globalConfig) { // if $items are not array of values, we have received query object if ($items instanceof \ADT\BaseQuery\BaseQuery) { - AjaxSelect\Traits\OrByIdFilterTrait::applyOrByIdFilter($config, $container, $name, $items); + if ($items instanceof AjaxSelect\Interfaces\OrdByIdFilterInterface) { + $items->applyOrByIdFilter($config, $container, $name); + } if ($items->callSelectPairsAuto()) { $items->selectPairs(); diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index f189e99..f553543 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -71,7 +71,9 @@ public function areValidValues(array $values) { $this->filterQueryObject($query); - AjaxSelect\Traits\OrByIdFilterTrait::applyOrByIdFilter($this->config, $form, $control->getName(), $query); + if ($query instanceof AjaxSelect\Interfaces\OrdByIdFilterInterface) { + $query->applyOrByIdFilter($this->config, $form, $control->getName()); + } foreach ($query->fetch() as $row) { // pouze selectnuté jsou validní diff --git a/src/Components/AjaxSelect/Interfaces/OrByIdFilterInterface.php b/src/Components/AjaxSelect/Interfaces/OrByIdFilterInterface.php new file mode 100644 index 0000000..c7238ad --- /dev/null +++ b/src/Components/AjaxSelect/Interfaces/OrByIdFilterInterface.php @@ -0,0 +1,9 @@ +inputName is included in items. if ($config[AjaxSelect\DI\AjaxSelectExtension::CONFIG_OR_BY_ID_FILTER] && method_exists($form, 'getEntity') && !empty($form->getEntity())) { @@ -24,9 +20,8 @@ public static function applyOrByIdFilter(array $config, \Nette\Forms\Container $ } if (!empty($defaultValue)) { - $query->orById($defaultValue); + $this->orById($defaultValue); } } } - } From 34d239886b639d324712c0d4255c3d93173d5430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 14 Jul 2024 08:51:11 +0200 Subject: [PATCH 06/20] fix --- src/Components/AjaxSelect/Interfaces/OrByIdFilterInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/AjaxSelect/Interfaces/OrByIdFilterInterface.php b/src/Components/AjaxSelect/Interfaces/OrByIdFilterInterface.php index c7238ad..cd49ac3 100644 --- a/src/Components/AjaxSelect/Interfaces/OrByIdFilterInterface.php +++ b/src/Components/AjaxSelect/Interfaces/OrByIdFilterInterface.php @@ -2,7 +2,7 @@ namespace ADT\Components\AjaxSelect\Interfaces; -interface OrdByIdFilterInterface +interface OrByIdFilterInterface { public function orById($id): static; public function applyOrByIdFilter(array $config, \Nette\Forms\Container $form, string $attributeName); From 5fcf8001a77fa1e122446ce7cda5110342aa6e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 14 Jul 2024 09:38:15 +0200 Subject: [PATCH 07/20] refactorization --- .../AjaxSelect/Entities/AbstractEntity.php | 19 ++++++------------- .../Traits/AjaxServiceControlTrait.php | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index f553543..b8c3898 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -6,14 +6,16 @@ use Nette\Application\UI\Presenter; use Nette\SmartObject; -abstract class AbstractEntity { - +abstract class AbstractEntity +{ use SmartObject; const DATA_ATTRIBUTE_NAME = 'data-adt-ajax-select'; - const OPTION_QUERY = 'q'; + public abstract function formatValues($values): array; + public abstract function hydrateValues($values): array; + /** @var string */ protected $name; @@ -107,18 +109,9 @@ public function findValues($limit) { ->applyPaging(0, $limit) ->toArray(); - return array_map(function ($row) { - return $row->getId(); - }, $rows); + return $rows; } - /** - * @internal - * @param array $values - * @return array List of items. - */ - public abstract function formatValues($values); - /** * @internal * @param array $values diff --git a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php index b3ed411..100d0ec 100644 --- a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php +++ b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php @@ -53,7 +53,7 @@ protected function processValues($values) { $validValues = array_merge($validValues, $invalidValues); } - $validItems = $this->getAjaxEntity()->formatValues($validValues); + $validItems = $this->getAjaxEntity()->formatValues($this->getAjaxEntity()->hydrateValues($validValues)); // add to list of valid values $this->setItems($this->getItems() + $validItems); From 45bbea05d4a807667c4f50b4fd23c4c30666b5c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 14 Jul 2024 10:18:06 +0200 Subject: [PATCH 08/20] refactorization --- composer.json | 2 +- .../AjaxSelect/Entities/AbstractEntity.php | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 819a125..9afa69f 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "nette/di": "^3.0", "nette/utils": "^3.0 | ^4.0", "nette/application": "*", - "adt/base-query": "^1.7" + "adt/doctrine-components": "^2.9" }, "autoload": { "psr-4": { diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index b8c3898..51ccf0a 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -3,6 +3,7 @@ namespace ADT\Components\AjaxSelect\Entities; use ADT\Components\AjaxSelect; +use ADT\DoctrineComponents\QueryObject; use Nette\Application\UI\Presenter; use Nette\SmartObject; @@ -16,6 +17,12 @@ abstract class AbstractEntity public abstract function formatValues($values): array; public abstract function hydrateValues($values): array; + protected abstract function createQueryObject(): QueryObject; + /** + * @param \ADT\BaseQuery\BaseQuery $query + */ + protected abstract function filterQueryObject($query); + /** @var string */ protected $name; @@ -135,16 +142,6 @@ public function formatJsonValues($values) { return $result; } - /** - * @return \ADT\BaseQuery\BaseQuery freshly created QO without filters - */ - protected abstract function createQueryObject(); - - /** - * @param \ADT\BaseQuery\BaseQuery $query - */ - protected abstract function filterQueryObject($query); - /** * @param string $option * @param mixed $value From 2cc6b5d63f4c8f64c2f85ee462096286250ebd07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 14 Jul 2024 21:17:13 +0200 Subject: [PATCH 09/20] refactorization --- src/Components/AjaxSelect/Entities/AbstractEntity.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index 51ccf0a..d6a8ada 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -18,10 +18,6 @@ public abstract function formatValues($values): array; public abstract function hydrateValues($values): array; protected abstract function createQueryObject(): QueryObject; - /** - * @param \ADT\BaseQuery\BaseQuery $query - */ - protected abstract function filterQueryObject($query); /** @var string */ protected $name; @@ -78,7 +74,9 @@ public function areValidValues(array $values) { $query = $this->createQueryObject() ->byId($values); - $this->filterQueryObject($query); + if (method_exists($this, 'filterQueryObject')) { + $this->filterQueryObject($query); + } if ($query instanceof AjaxSelect\Interfaces\OrdByIdFilterInterface) { $query->applyOrByIdFilter($this->config, $form, $control->getName()); From 319a5a22f5c11bd01049c0bbb621044c71a325de Mon Sep 17 00:00:00 2001 From: Korca Date: Thu, 7 Nov 2024 09:33:41 +0100 Subject: [PATCH 10/20] add-aria-setsize-and-aria-posinset-attr-to-results --- src/Components/AjaxSelect/Entities/AbstractEntity.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index f189e99..5431777 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -125,18 +125,20 @@ public abstract function formatValues($values); public function formatJsonValues($values) { $result = [ ]; $titles = $this->formatValues($values); - + $count = count($titles); + $i = 1; foreach ($titles as $id => $item) { if (!is_array($item)) { $item = [ 'text' => $item, ]; } - $item['id'] = $id; + $item['aria-posinset'] = $i; + $item['aria-setsize'] = $count; $result[] = $item; + $i++; } - return $result; } From 4fbe51b023517a1ee1ee4202864b88fd4ada5ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Konvi=C4=8Dka?= Date: Tue, 19 Nov 2024 12:40:14 +0100 Subject: [PATCH 11/20] Added check before calling method_exists --- src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php b/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php index e3821b0..52edf21 100644 --- a/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php +++ b/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php @@ -19,7 +19,7 @@ public static function applyOrByIdFilter(array $config, \Nette\Forms\Container $ $defaultValue = $form->getEntity()->{'get' . ucfirst($attributeName)}(); //It can be Kdyby\Doctrine\Collections\Readonly\ReadOnlyCollectionWrapper - if (method_exists($defaultValue, 'toArray')) { + if ($defaultValue && method_exists($defaultValue, 'toArray')) { $defaultValue = $defaultValue->toArray(); } From 35f3cc0fe84e358a1b09f1c96853ce0cb098754c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Konvi=C4=8Dka?= Date: Mon, 6 Jan 2025 13:02:43 +0100 Subject: [PATCH 12/20] Check array before calling method_exists toArray --- src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php b/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php index 22591f0..c4b89d4 100644 --- a/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php +++ b/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php @@ -15,7 +15,7 @@ public function applyOrByIdFilter(array $config, \Nette\Forms\Container $form, s $defaultValue = $form->getEntity()->{'get' . ucfirst($attributeName)}(); //It can be Kdyby\Doctrine\Collections\Readonly\ReadOnlyCollectionWrapper - if ($defaultValue && method_exists($defaultValue, 'toArray')) { + if ($defaultValue && !is_array($defaultValue) && method_exists($defaultValue, 'toArray')) { $defaultValue = $defaultValue->toArray(); } From 08d3b2eabb6075cf983389057d4647b8b076d504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 26 Jan 2025 13:24:05 +0100 Subject: [PATCH 13/20] Update AjaxService.php --- src/Components/AjaxSelect/Services/AjaxService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/AjaxSelect/Services/AjaxService.php b/src/Components/AjaxSelect/Services/AjaxService.php index b309862..54aff8c 100644 --- a/src/Components/AjaxSelect/Services/AjaxService.php +++ b/src/Components/AjaxSelect/Services/AjaxService.php @@ -32,7 +32,7 @@ public function addEntityFactory($entityName, $entityFactory) { * @param AjaxSelect\Interfaces\IAjaxServiceControl $clientControl * @return AjaxSelect\Entities\AbstractEntity */ - public function createEntity($entityName, AjaxSelect\Interfaces\IAjaxServiceControl $clientControl = NULL) { + public function createEntity($entityName, ?AjaxSelect\Interfaces\IAjaxServiceControl $clientControl = NULL) { if ($entityName instanceof AjaxSelect\Entities\AbstractEntity) { $entity = $entityName; } else { From 460dc272cb951859bbe5261ce9f1ff03c6719d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 11 May 2025 12:54:50 +0200 Subject: [PATCH 14/20] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9afa69f..b78d4b6 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "nette/di": "^3.0", "nette/utils": "^3.0 | ^4.0", "nette/application": "*", - "adt/doctrine-components": "^2.9" + "adt/doctrine-components": "^2.9|^3.0" }, "autoload": { "psr-4": { From 4a58025a41419f7eff7edd9654905d70dbcb7ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Thu, 15 May 2025 16:03:16 +0200 Subject: [PATCH 15/20] Passes form values to entity hydration Ensures that form values are available during entity hydration, allowing for more context-aware data handling within the AjaxSelect component. This allows hydration logic to take form context into consideration when formatting JSON values, which ensures proper data handling and rendering of selected options. --- src/Components/AjaxSelect/Entities/AbstractEntity.php | 9 +++++---- .../AjaxSelect/Traits/AjaxServiceControlTrait.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index 33fe221..607950b 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -15,7 +15,7 @@ abstract class AbstractEntity const OPTION_QUERY = 'q'; public abstract function formatValues($values): array; - public abstract function hydrateValues($values): array; + public abstract function hydrateValues($values, array $formValues = []): array; protected abstract function createQueryObject(): QueryObject; @@ -122,9 +122,9 @@ public function findValues($limit) { * @param array $values * @return array List of items. */ - public function formatJsonValues($values) { + public function formatJsonValues($values, array $formValues = []) { $result = [ ]; - $titles = $this->formatValues($values); + $titles = $this->formatValues($this->hydrateValues($values, $formValues)); $count = count($titles); $i = 1; foreach ($titles as $id => $item) { @@ -200,7 +200,8 @@ public function done() { ? $this->formatJsonValues( is_array($controlValue) ? $controlValue - : [ $controlValue ] + : [ $controlValue ], + $control->getForm()->getUntrustedValues('array') ) : [], 'queryParam' => static::OPTION_QUERY, diff --git a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php index 100d0ec..934e719 100644 --- a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php +++ b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php @@ -53,7 +53,7 @@ protected function processValues($values) { $validValues = array_merge($validValues, $invalidValues); } - $validItems = $this->getAjaxEntity()->formatValues($this->getAjaxEntity()->hydrateValues($validValues)); + $validItems = $this->getAjaxEntity()->formatValues($this->getAjaxEntity()->hydrateValues($validValues, $this->getForm()->getUntrustedValues('array'))); // add to list of valid values $this->setItems($this->getItems() + $validItems); From 2d680f3f69b02d5667cf12dac6fe3c675edb441f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Thu, 15 May 2025 16:13:00 +0200 Subject: [PATCH 16/20] Uses trusted form values Updates the code to use trusted form values instead of untrusted values when hydrating and formatting data. This change ensures that the application processes data that has been properly validated, preventing potential security issues and data integrity problems. --- src/Components/AjaxSelect/Entities/AbstractEntity.php | 2 +- src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index 607950b..1bad32e 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -201,7 +201,7 @@ public function done() { is_array($controlValue) ? $controlValue : [ $controlValue ], - $control->getForm()->getUntrustedValues('array') + $control->getForm()->getValues('array') ) : [], 'queryParam' => static::OPTION_QUERY, diff --git a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php index 934e719..f323d38 100644 --- a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php +++ b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php @@ -53,7 +53,7 @@ protected function processValues($values) { $validValues = array_merge($validValues, $invalidValues); } - $validItems = $this->getAjaxEntity()->formatValues($this->getAjaxEntity()->hydrateValues($validValues, $this->getForm()->getUntrustedValues('array'))); + $validItems = $this->getAjaxEntity()->formatValues($this->getAjaxEntity()->hydrateValues($validValues, $this->getForm()->getValues('array'))); // add to list of valid values $this->setItems($this->getItems() + $validItems); From 330c28691040472332ff7bc6ad77539eb74b30ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 15 Jun 2025 20:54:27 +0200 Subject: [PATCH 17/20] Updates doctrine-components dependency Updates the doctrine-components dependency to the latest major version. This change removes the previous range constraint and ensures compatibility with newer features and bug fixes. Also updates namespace of QueryObject class. --- composer.json | 2 +- src/Components/AjaxSelect/Entities/AbstractEntity.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index b78d4b6..2416ad3 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "nette/di": "^3.0", "nette/utils": "^3.0 | ^4.0", "nette/application": "*", - "adt/doctrine-components": "^2.9|^3.0" + "adt/doctrine-components": "^3.0" }, "autoload": { "psr-4": { diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index 1bad32e..4f637f8 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -3,7 +3,7 @@ namespace ADT\Components\AjaxSelect\Entities; use ADT\Components\AjaxSelect; -use ADT\DoctrineComponents\QueryObject; +use ADT\DoctrineComponents\QueryObject\QueryObject; use Nette\Application\UI\Presenter; use Nette\SmartObject; From 0ae2a4de5d6e998f00b74a97d477dce71f133af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sat, 31 Jan 2026 08:36:14 +0100 Subject: [PATCH 18/20] Updates dependencies and form validation Updates the dependencies to PHP 8.3 and a new forms component. Uses validated form values instead of all values when formatting and hydrating values, improving data handling and security. --- composer.json | 4 ++-- src/Components/AjaxSelect/Entities/AbstractEntity.php | 2 +- src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 2416ad3..432a857 100644 --- a/composer.json +++ b/composer.json @@ -4,8 +4,8 @@ "type": "library", "license": ["MIT", "BSD-3-Clause", "GPL-2.0", "GPL-3.0"], "require": { - "php": ">=7.1", - "nette/forms": "^3.0", + "php": ">=8.3", + "adt/nette-forms-components": "^2.3", "nette/di": "^3.0", "nette/utils": "^3.0 | ^4.0", "nette/application": "*", diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index 4f637f8..2bd32cd 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -201,7 +201,7 @@ public function done() { is_array($controlValue) ? $controlValue : [ $controlValue ], - $control->getForm()->getValues('array') + $control->getForm()->getValidatedValues('array') ) : [], 'queryParam' => static::OPTION_QUERY, diff --git a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php index f323d38..4e7f639 100644 --- a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php +++ b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php @@ -53,7 +53,7 @@ protected function processValues($values) { $validValues = array_merge($validValues, $invalidValues); } - $validItems = $this->getAjaxEntity()->formatValues($this->getAjaxEntity()->hydrateValues($validValues, $this->getForm()->getValues('array'))); + $validItems = $this->getAjaxEntity()->formatValues($this->getAjaxEntity()->hydrateValues($validValues, $this->getForm()->getValidatedValues('array'))); // add to list of valid values $this->setItems($this->getItems() + $validItems); From d0fd9e1e1c5b649579a720d8335bc073131da9f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Wed, 24 Jun 2026 08:58:32 +0200 Subject: [PATCH 19/20] Introduce Nette Forms and improve type consistency Adds the `nette/forms` dependency to expand form capabilities. Updates `getHttpData` method signature with type hints for clarity and consistency. --- composer.json | 5 +++-- src/Components/AjaxSelect/Traits/InvalidSetValueTrait.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 432a857..38a0b26 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,9 @@ "nette/di": "^3.0", "nette/utils": "^3.0 | ^4.0", "nette/application": "*", - "adt/doctrine-components": "^3.0" - }, + "adt/doctrine-components": "^3.0", + "nette/forms": "^3.3" + }, "autoload": { "psr-4": { "ADT\\": "src/" diff --git a/src/Components/AjaxSelect/Traits/InvalidSetValueTrait.php b/src/Components/AjaxSelect/Traits/InvalidSetValueTrait.php index e2f5afe..6f75a61 100644 --- a/src/Components/AjaxSelect/Traits/InvalidSetValueTrait.php +++ b/src/Components/AjaxSelect/Traits/InvalidSetValueTrait.php @@ -35,7 +35,7 @@ public function setInvalidValueMode($mode) { return $this; } - protected abstract function getHttpData($type, ?string $htmlTail = NULL); + protected abstract function getHttpData(int $type, ?string $htmlTail = NULL): mixed; protected abstract function isDisabled(); /** From 4316fe6e15c2192644ff0ce1e3d8e1c9ac716e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Wed, 24 Jun 2026 09:05:31 +0200 Subject: [PATCH 20/20] Pin `nette/forms` dependency to `3.2.x` series Restricts the allowed versions to `^3.2.9` to prevent potential compatibility issues with `3.3.x` releases. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 38a0b26..80c71a3 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "nette/utils": "^3.0 | ^4.0", "nette/application": "*", "adt/doctrine-components": "^3.0", - "nette/forms": "^3.3" + "nette/forms": "^3.2.9" }, "autoload": { "psr-4": {