From e42ee936dd3e800cbfd4d2bbfff78bd9709649a9 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 | 3 +++ inc/container.class.php | 6 +++++- inc/field.class.php | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee6bf7bd..adf4880d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Add compatibility with GLPI `CustomAsset` +### Fixed + +- 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 f31e4241..62070144 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1354,7 +1354,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 0939fe9b..adf19da8 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -1279,6 +1279,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 8efab96115297c873197422ab7d5aef0ac0d24ac 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 adf19da8..f07d7f79 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -1278,7 +1278,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 5117dfd0dc307418e4dba8a79fc382366103866a 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 62070144..9c1230d8 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1355,9 +1355,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)) {