feat: Add multi-select dropdown support for Forms questions#1192
Open
RPGMais wants to merge 3 commits intopluginsGLPI:mainfrom
Open
feat: Add multi-select dropdown support for Forms questions#1192RPGMais wants to merge 3 commits intopluginsGLPI:mainfrom
RPGMais wants to merge 3 commits intopluginsGLPI:mainfrom
Conversation
Fields plugin dropdowns with multiple=1 now work correctly in GLPI Forms. Adds "Allow multiple options" toggle to the form editor when using the "Campo" question type, properly handles array answers in the save pipeline, and applies multi-select values correctly when creating tickets.
1539ca7 to
5b47bc7
Compare
- Include 'tab' type containers in getAvailableBlocks() so fields from tab containers can be used in Forms questions (not only 'dom' type) - Fix strlen(): array given error in fields.html.twig by passing the decoded array value via the 'values' option instead of the value parameter when rendering multi-select dropdowns (both custom and GLPI core dropdown types)
- Add trailing comma in MultipleChoiceFromValuesConditionHandler arg - Collapse nested if into single condition (Rector) - Use first-class callable intval(...) instead of string 'intval' (Rector) - Add blank line before return in getDropdownValuesForCondition (Rector)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fields plugin dropdowns configured with
multiple=1now work correctly when used in GLPI Forms through thePluginFieldsQuestionType("Campo" question type).Problem: When a Fields dropdown with multi-selection enabled was added to a Form, there was no way to enable multi-select behavior in the form editor. The
PluginFieldsQuestionTypelacked:QuestionTypeDropdownhas)prepareEndUserAnswer()PluginFieldsDestinationFieldSolution (3 files, 115 lines added):
questiontypeextradataconfig.class.php-- Addedis_multiplefield to the serialized config (defaultfalse, fully backward-compatible)questiontype.class.php-- AddedrenderAdministrationOptionsTemplate()with "Allow multiple options" toggle, overrodeprepareEndUserAnswer()to normalize multi-select arrays, updatedrenderEndUserTemplate()andrenderAdministrationTemplate()to respect the flag, addedMultipleChoiceFromValuesConditionHandlerfor multi-select fieldsdestinationfield.class.php-- Handle bothdropdownanddropdown-Xtypes withstr_starts_with(),json_encodearray values for multi-select fields when creating ticketsHow it works
Design decisions
multipleDB flag, giving form editors flexibility to enable/disable multi-select per question regardless of the field definitionisMultipleForQuestion()checks both the form config (extra_data.is_multiple) and the field definition (field.multiple) as fallbackQuestionTypeDropdownimplementation (same toggle markup, same condition handler class)No breaking changes
is_multipledefaults tofalseinjsonDeserialize(), so existing questions are unaffecteddestinationfield.class.phpchange also fixes theelseifto usestr_starts_with('dropdown')instead of exact match== 'dropdown', correctly handlingdropdown-Xtypes (e.g.,dropdown-User)Test plan
multiple=1in a block assigned to Ticketsextra_datacontainsis_multiple: 1is_multiplestill work as single-select