From 46befd12b822b8f05ce795f02c65d2d0d78876cd Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 5 Feb 2026 14:00:53 +0100 Subject: [PATCH 1/3] fix(dropdown): handle empty default value to prevent error --- CHANGELOG.md | 1 + inc/container.class.php | 6 +++++- inc/field.class.php | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3d4749d..dd71e9d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fix migration error caused by unknown itemtype in containers +- Fix empty default value in multiple dropdown fields ## [1.23.2] - 2025-12-22 diff --git a/inc/container.class.php b/inc/container.class.php index 083094fa..3561db79 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1369,7 +1369,11 @@ public function updateFieldsValues($data, $itemtype, $massiveaction = false) $data[$field_name] = json_encode(array_values(array_unique(array_merge($existing_values, $new_values)))); } else { - $data[$field_name] = json_encode($data[$field_name]); + $value = $data[$field_name]; + if (!is_array($value)) { + $value = ($value === '' || $value === null) ? [] : [$value]; + } + $data[$field_name] = json_encode($value); } } elseif (array_key_exists('_' . $field_name . '_defined', $data)) { $data[$field_name] = json_encode([]); diff --git a/inc/field.class.php b/inc/field.class.php index c33051df..ba783c59 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -1277,6 +1277,8 @@ public static function prepareHtmlFields( // // -> Decode it only if it is not already an array. $value = json_decode((string) $value); + $decoded = json_decode((string) $value, true); + $value = is_array($decoded) ? $decoded : []; } $field['value'] = $value; From bbd5708be7d8ed389110b0ef62a40ab13260bf92 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 5 Feb 2026 14:16:35 +0100 Subject: [PATCH 2/3] fix --- inc/field.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/inc/field.class.php b/inc/field.class.php index ba783c59..8beb9362 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -1276,7 +1276,6 @@ public static function prepareHtmlFields( // - either from a previous input (it will be an array). // // -> Decode it only if it is not already an array. - $value = json_decode((string) $value); $decoded = json_decode((string) $value, true); $value = is_array($decoded) ? $decoded : []; } From f00070f48e46710bce90154153c9f865cb5339ce Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 5 Feb 2026 14:19:45 +0100 Subject: [PATCH 3/3] fix --- inc/container.class.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index 3561db79..15e3a798 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1370,9 +1370,7 @@ public function updateFieldsValues($data, $itemtype, $massiveaction = false) } else { $value = $data[$field_name]; - if (!is_array($value)) { - $value = ($value === '' || $value === null) ? [] : [$value]; - } + $value = is_array($value) ? $value : []; $data[$field_name] = json_encode($value); } } elseif (array_key_exists('_' . $field_name . '_defined', $data)) {