From 644560837d300def4458d3168f67cebb0685ebd1 Mon Sep 17 00:00:00 2001 From: Antoine Hurard Date: Mon, 19 Feb 2024 17:33:56 +0100 Subject: [PATCH] refactor: tagbox using tag mode can now be disabled / enabled --- .../filter-builder-modal.component.ts | 1 + .../src/lib/survey/widgets/tagbox-widget.ts | 83 +++++++++++++------ 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/libs/shared/src/lib/components/dashboard-filter/filter-builder-modal/filter-builder-modal.component.ts b/libs/shared/src/lib/components/dashboard-filter/filter-builder-modal/filter-builder-modal.component.ts index bdb2342d7e..dc6ae6712f 100644 --- a/libs/shared/src/lib/components/dashboard-filter/filter-builder-modal/filter-builder-modal.component.ts +++ b/libs/shared/src/lib/components/dashboard-filter/filter-builder-modal/filter-builder-modal.component.ts @@ -113,6 +113,7 @@ const CORE_QUESTION_ALLOWED_PROPERTIES = [ 'readOnly', 'isRequired', 'placeHolder', + 'useSummaryTagMode', 'enableIf', 'visibleIf', 'tooltip', diff --git a/libs/shared/src/lib/survey/widgets/tagbox-widget.ts b/libs/shared/src/lib/survey/widgets/tagbox-widget.ts index 1fb185b3e0..f2e882a1b9 100644 --- a/libs/shared/src/lib/survey/widgets/tagbox-widget.ts +++ b/libs/shared/src/lib/survey/widgets/tagbox-widget.ts @@ -43,30 +43,44 @@ export const init = ( return question.getType() === componentName; }, init: () => { - if (Serializer.findClass(componentName)) return; - Serializer.addClass( - componentName, - [ - { name: 'hasOther:boolean', visible: false }, - { name: 'hasSelectAll:boolean', visible: false }, - { name: 'hasNone:boolean', visible: false }, - { name: 'otherText', visible: false }, - { name: 'selectAllText', visible: false }, - { name: 'noneText', visible: false }, - ], - () => null, - 'checkbox' - ); - Serializer.addProperty(componentName, { - name: 'placeholder', - category: 'general', - default: '', - }); - Serializer.addProperty(componentName, { - name: 'allowAddNewTag:boolean', - category: 'general', - default: false, - }); + if (Serializer.findClass(componentName)) { + Serializer.addProperty(componentName, { + name: 'useSummaryTagMode', + type: 'boolean', + category: 'general', + default: false, + }); + } else { + Serializer.addClass( + componentName, + [ + { name: 'hasOther:boolean', visible: false }, + { name: 'hasSelectAll:boolean', visible: false }, + { name: 'hasNone:boolean', visible: false }, + { name: 'otherText', visible: false }, + { name: 'selectAllText', visible: false }, + { name: 'noneText', visible: false }, + ], + () => null, + 'checkbox' + ); + Serializer.addProperty(componentName, { + name: 'placeholder', + category: 'general', + default: '', + }); + Serializer.addProperty(componentName, { + name: 'useSummaryTagMode', + type: 'boolean', + category: 'general', + default: false, + }); + Serializer.addProperty(componentName, { + name: 'allowAddNewTag:boolean', + category: 'general', + default: false, + }); + } }, isDefaultRender: false, afterRender: (question: any, el: HTMLElement): void => { @@ -142,6 +156,18 @@ export const init = ( tagboxInstance.disabled = value; } ); + question.registerFunctionOnPropertyValueChanged( + 'useSummaryTagMode', + (value: boolean) => { + if (value) { + tagboxInstance.tagMapper = (tags: any[]) => { + return tags.length < 2 ? tags : [tags]; + }; + } else { + tagboxInstance.tagMapper = () => null; + } + } + ); if (question.visibleChoices.length) { updateChoices(tagboxInstance, question, currentSearchValue); } @@ -186,9 +212,12 @@ export const init = ( tagboxInstance.valueField = 'value'; tagboxInstance.popupSettings = { appendTo: 'component' }; tagboxInstance.fillMode = 'none'; - tagboxInstance.tagMapper = (tags: any[]) => { - return tags.length < 2 ? tags : [tags]; - }; + if (question.useSummaryTagMode) { + tagboxInstance.tagMapper = (tags: any[]) => { + return tags.length < 2 ? tags : [tags]; + }; + } + return tagboxInstance; }; // ⚠ danger ⚠