Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Multi Dropdown): handle / save empty choice #733

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,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