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

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a7f25e951770_38267a5037444@gitlab-sidekiq-low-urgency-cpu-bound-v2-7774c44f54-4sw2q.mail>

Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
b1603b68 by Bruno Kambere at 2026-08-14T14:09:56+00:00
[FIX] Dynamic Items List: Fix Empty multi-select not being saved
---
* [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/b1603b68a1c78b4baa5bf33cd18a78ebdc3b22df

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