From 678804aa8c5c34843c894a749d82f78f6d4c5d75 Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Tue, 28 Nov 2023 11:52:40 +0100 Subject: [PATCH 1/4] fix(Multi Dropdown): handle / save empty choice --- inc/container.class.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/inc/container.class.php b/inc/container.class.php index 63018479..898b5e54 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1753,6 +1753,18 @@ private static function populateData($c_id, CommonDBTM $item) $data[$prefix_input] = $item->input[$prefix_input] ?? []; $data[$tag_input] = $item->input[$tag_input] ?? []; } + } else { + //managed multi dropdown field + if ($field['type'] == 'dropdown' && $field['multiple']) { + $multiple_key = sprintf('plugin_fields_%sdropdowns_id', $field['name']); + //values are defined by user + if (isset($item->input[$multiple_key])) { + $data[$multiple_key] = $item->input[$multiple_key]; + } else { //multi dropdown is empty or has been emptied + $data[$multiple_key] = []; + } + $has_fields = true; + } } } From 70eccaf73ba98fcb03be8ba8c5e3cf2d1c078c57 Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Thu, 7 Dec 2023 11:09:58 +0100 Subject: [PATCH 2/4] fix(Multi GLPI Item Dropdown): handle / save empty choice --- inc/container.class.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/inc/container.class.php b/inc/container.class.php index 898b5e54..5429ed64 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1765,6 +1765,19 @@ private static function populateData($c_id, CommonDBTM $item) } $has_fields = true; } + + //managed multi GLPI item dropdown field + if ( + preg_match('/^dropdown-(?.+)$/', $field['type'], $match) === 1 + && $field['multiple']) { + //values are defined by user + if (isset($item->input[$field['name']])) { + $data[$field['name']] = $item->input[$field['name']]; + } else { //multi dropdown is empty or has been emptied + $data[$field['name']] = []; + } + $has_fields = true; + } } } From 8be58ff288c2ec904c085e230559797106a4e12a Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Fri, 8 Dec 2023 08:48:08 +0100 Subject: [PATCH 3/4] refactor and comment --- inc/container.class.php | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index 5429ed64..0595e1d9 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1754,22 +1754,24 @@ private static function populateData($c_id, CommonDBTM $item) $data[$tag_input] = $item->input[$tag_input] ?? []; } } else { - //managed multi dropdown field - if ($field['type'] == 'dropdown' && $field['multiple']) { - $multiple_key = sprintf('plugin_fields_%sdropdowns_id', $field['name']); - //values are defined by user - if (isset($item->input[$multiple_key])) { - $data[$multiple_key] = $item->input[$multiple_key]; - } else { //multi dropdown is empty or has been emptied - $data[$multiple_key] = []; + //the absence of the field in the input may be due to the fact that the input allows multiple selection + // ex my_dom[] + //in these conditions, the input is never sent by the browser + if ($field['multiple']) { + //handle multi dropodwn field + if ($field['type'] == 'dropdown') { + $multiple_key = sprintf('plugin_fields_%sdropdowns_id', $field['name']); + //values are defined by user + if (isset($item->input[$multiple_key])) { + $data[$multiple_key] = $item->input[$multiple_key]; + } else { //multi dropdown is empty or has been emptied + $data[$multiple_key] = []; + } + $has_fields = true; } - $has_fields = true; - } - //managed multi GLPI item dropdown field - if ( - preg_match('/^dropdown-(?.+)$/', $field['type'], $match) === 1 - && $field['multiple']) { + //managed multi GLPI item dropdown field + if (preg_match('/^dropdown-(?.+)$/', $field['type'], $match) === 1) { //values are defined by user if (isset($item->input[$field['name']])) { $data[$field['name']] = $item->input[$field['name']]; @@ -1777,7 +1779,11 @@ private static function populateData($c_id, CommonDBTM $item) $data[$field['name']] = []; } $has_fields = true; + } } + + + } } From 6001e381f2207080ec5e46071ffef65a70681161 Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Fri, 8 Dec 2023 08:51:13 +0100 Subject: [PATCH 4/4] remove empty line --- inc/container.class.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index 0595e1d9..4207f3ee 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1781,9 +1781,6 @@ private static function populateData($c_id, CommonDBTM $item) $has_fields = true; } } - - - } }