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..9c1230d8 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1354,7 +1354,9 @@ 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]; + $value = is_array($value) ? $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..f07d7f79 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -1278,7 +1278,8 @@ 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 : []; } $field['value'] = $value;