[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [BP][FIX] Dynamic Items List: Fix Empty multi-select not being saved

"Bruno Kambere \(@kambereBr\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a8c66048d052_382189474658b9@gitlab-sidekiq-low-urgency-cpu-bound-v2-959bd5c78-xkkbt.mail>

Bruno Kambere pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki


Commits:
a6668c9c by Bruno Kambere at 2026-08-24T17:50:19+03:00
[BP][FIX] Dynamic Items List: Fix Empty multi-select not being saved

See merge request tikiwiki/tiki!10857

- - - - -


1 changed file:

- lib/core/Tracker/Field/DynamicList.php


Changes:

=====================================
lib/core/Tracker/Field/DynamicList.php
=====================================
@@ -185,10 +185,19 @@ class Tracker_Field_DynamicList extends \Tracker\Field\AbstractItemField impleme
     public function getFieldData(array $requestData = []): array
     {
         $ins_id = $this->getInsertId();
+
+        if (isset($requestData[$ins_id])) {
+            $value = $requestData[$ins_id];
+        } elseif (isset($requestData[$ins_id . '_old'])) {
+            // the field was in the form but nothing was selected: an empty multiple select submits no key at all
+            $value = $this->canHaveMultipleValues() ? [] : '';
+        } else {
+            // the field was not part of this form, keep the stored value
+            $value = $this->getValue();
+        }
+
         $data = [
-            'value' => (isset($requestData[$ins_id]))
-                ? $requestData[$ins_id]
-                : $this->getValue(),
+            'value' => $value,
         ];
 
         if ($this->trackerField->getOption('selectMultipleValues') && ! is_array($data['value'])) {
@@ -351,10 +360,14 @@ if( $("input[name=\'' . $filterFieldHereName . '\'], select[name=\'' . $filterFi
 $("input[name=\'' . $filterFieldHereName . '\'], select[name=\'' . $filterFieldHereName . '\']").trigger("change", "initial");
 ', 1);
 
+        // an empty multiple select (or transfer list) submits no key at all, which getFieldData() would otherwise read as
+        // "field not in the request" and restore the stored value. This marker tells it the field was in the form.
+        $oldMarker = '<input type="hidden" name="' . $this->getInsertId() . '_old" value="1">';
+
         if ($this->trackerField->getOption('inputtype') === 't') {
             $smarty = TikiLib::lib('smarty');
 
-            return smarty_function_jstransfer_list([
+            return $oldMarker . smarty_function_jstransfer_list([
                 'fieldName' => $insertId,
                 'data' => [],
                 'defaultSelected' => $this->getValue(),
@@ -368,7 +381,7 @@ $("input[name=\'' . $filterFieldHereName . '\'], select[name=\'' . $filterFieldH
             ], $smarty->getEmptyInternalTemplate());
         }
 
-        return '<select class="form-control"' . $multiple . ' name="' . $insertId . '"></select>';
+        return $oldMarker . '<select class="form-control"' . $multiple . ' name="' . $insertId . '"></select>';
     }
 
 



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/a6668c9c65555cc4b01b61da4f8269ddecd4940c

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/a6668c9c65555cc4b01b61da4f8269ddecd4940c
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.