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 missing form data when multi-select empty #17074

Merged
merged 1 commit into from May 16, 2024

Conversation

cconard96
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -

When a multiple-select dropdown has no options selected, no form data is sent to GLPI so that field is ignored. This made it impossible to handle removing all selections from a dropdown unless the missing field was treated specially as if it were an empty selection. That special handling is not correct though as partial updates via the API(s) are possible and failing to specify a multiselect field in an API update request should not delete the value.

The fix adds a hidden input with the same name just before the select element in the DOM. If the browser decides to send the data for the select, the hidden input is ignored.

This may cause some breaks besides the one I found immediately for the devices_in_menu config options. On some other dropdowns it seemed to work without issue. Other cases may be found as work on the UI continues, during beta testing, or through added E2E tests.

Copy link
Member

@cedric-anne cedric-anne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can detect existing hack by searching for exportArrayToDB() usage preceded by a isset() on an input with a different key. For instance:

        if (isset($input["_helpdesk_item_types"])) {
            if ((!isset($input["helpdesk_item_type"])) || (!is_array($input["helpdesk_item_type"]))) {
                $input["helpdesk_item_type"] = [];
            }
           // Linear_HIT: $input["helpdesk_item_type"] = array_keys($input["helpdesk_item_type"]
            $input["helpdesk_item_type"] = exportArrayToDB($input["helpdesk_item_type"]);
        }

helpdesk_item_type is used only if _helpdesk_item_types is set.

@cconard96 cconard96 force-pushed the fix/empty_multiselect branch 2 times, most recently from 64f7c2a to a1b6296 Compare May 8, 2024 23:18
@cedric-anne cedric-anne merged commit b73302f into glpi-project:main May 16, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants