Skip to content

Commit

Permalink
Handle / save empty choice for dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
stonebuzz authored Feb 21, 2024
1 parent 5024bf1 commit 393c502
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,34 @@ private static function populateData($c_id, CommonDBTM $item)
$data[$prefix_input] = $item->input[$prefix_input] ?? [];
$data[$tag_input] = $item->input[$tag_input] ?? [];
}
} else {
//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;
}

//managed multi GLPI item dropdown field
if (preg_match('/^dropdown-(?<type>.+)$/', $field['type'], $match) === 1) {
//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;
}
}
}
}

Expand Down

0 comments on commit 393c502

Please sign in to comment.