Skip to content

Commit 3460cf7

Browse files
authored
fix(dropdown): handle empty default value to prevent error (#1128)
* fix(dropdown): handle empty default value to prevent error * fix * fix
1 parent b126743 commit 3460cf7

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
### Fixed
1515

1616
- Fix migration error caused by unknown itemtype in containers
17+
- Fix empty default value in multiple dropdown fields
1718

1819
## [1.23.2] - 2025-12-22
1920

inc/container.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,9 @@ public function updateFieldsValues($data, $itemtype, $massiveaction = false)
13691369
$data[$field_name] = json_encode(array_values(array_unique(array_merge($existing_values, $new_values))));
13701370

13711371
} else {
1372-
$data[$field_name] = json_encode($data[$field_name]);
1372+
$value = $data[$field_name];
1373+
$value = is_array($value) ? $value : [];
1374+
$data[$field_name] = json_encode($value);
13731375
}
13741376
} elseif (array_key_exists('_' . $field_name . '_defined', $data)) {
13751377
$data[$field_name] = json_encode([]);

inc/field.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,8 @@ public static function prepareHtmlFields(
12761276
// - either from a previous input (it will be an array).
12771277
//
12781278
// -> Decode it only if it is not already an array.
1279-
$value = json_decode((string) $value);
1279+
$decoded = json_decode((string) $value, true);
1280+
$value = is_array($decoded) ? $decoded : [];
12801281
}
12811282

12821283
$field['value'] = $value;

0 commit comments

Comments
 (0)