From 9285b87a92b46a99e234c5d79a14e86c12318b74 Mon Sep 17 00:00:00 2001 From: ralf Date: Thu, 10 Mar 2022 15:48:27 +0200 Subject: [PATCH] implement multiple attribute for et2-select reflecting it to selectbox fixing TypeError set_multiple is not a function --- api/js/etemplate/Et2Select/Et2Select.ts | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/api/js/etemplate/Et2Select/Et2Select.ts b/api/js/etemplate/Et2Select/Et2Select.ts index 7898400343..0ae6f9b882 100644 --- a/api/js/etemplate/Et2Select/Et2Select.ts +++ b/api/js/etemplate/Et2Select/Et2Select.ts @@ -89,6 +89,29 @@ export class Et2Select extends Et2WidgetWithSelect return this._inputNode; } + static get properties() + { + return { + ...super.properties, + /** + * Toggle between single and multiple selection + */ + multiple: { + type: Boolean, + reflect: true, + }, + } + } + + set_multiple(multi) + { + if (typeof multi !== 'boolean') + { + multi = multi && !(multi === 'false' || multi === '0'); + } + this.multiple = multi; + } + /** @param {import('@lion/core').PropertyValues } changedProperties */ updated(changedProperties : PropertyValues) { @@ -106,6 +129,12 @@ export class Et2Select extends Et2WidgetWithSelect // Re-set value, the option for it may have just shown up this._inputNode.value = this.modelValue || ""; } + + // propagate multiple to selectbox + if (changedProperties.has('multiple')) + { + this._inputNode.multiple = this.multiple; + } } _emptyLabelTemplate() : TemplateResult