[TikiWiki-commits] [Git][tikiwiki/tiki][27.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 <6a8f5bec7a580_381662dc063416@gitlab-sidekiq-low-urgency-cpu-bound-v2-64bbd65c45-s956v.mail>

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


Commits:
117f1a26 by Bruno Kambere at 2026-08-26T19:46: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'])) {
@@ -350,10 +359,14 @@ if( $("input[name=ins_' . $filterFieldIdHere . '], select[name=ins_' . $filterFi
 $("input[name=ins_' . $filterFieldIdHere . '], select[name=ins_' . $filterFieldIdHere . ']").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(),
@@ -365,7 +378,7 @@ $("input[name=ins_' . $filterFieldIdHere . '], select[name=ins_' . $filterFieldI
             ], $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/117f1a260e9d5a376596db5b54f4bd5f7f3f6809

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/117f1a260e9d5a376596db5b54f4bd5f7f3f6809
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.