diff --git a/api/js/etemplate/Et2Email/Et2Email.ts b/api/js/etemplate/Et2Email/Et2Email.ts index c79fd1fa1e..774d67933e 100644 --- a/api/js/etemplate/Et2Email/Et2Email.ts +++ b/api/js/etemplate/Et2Email/Et2Email.ts @@ -242,6 +242,18 @@ export class Et2Email extends Et2InputWidget(LitElement) implements SearchMixinI document.removeEventListener('focusin', this.handleLostFocus); } + set_value(_value) + { + if (!Array.isArray(_value)) + { + this.value = parseEmailsString(_value, this.allowPlaceholder); + } + else + { + this.value = _value; + } + } + willUpdate(changedProperties : PropertyValues) { super.willUpdate(changedProperties); @@ -1131,5 +1143,20 @@ export class Et2Email extends Et2InputWidget(LitElement) implements SearchMixinI } } -// @ts-ignore TypeScript is not recognizing that this widget is a LitElement -customElements.define("et2-email", Et2Email); \ No newline at end of file +customElements.define("et2-email", Et2Email); + +/** + * Parse string that may contain multiple comma separated email addresses into an array + * + * @param {string} value + * @returns {string[]} + * @protected + */ +function parseEmailsString(value : string, allowPlaceholder = false) : string[] +{ + if (!value) return []; + let preg = allowPlaceholder ? IsEmail.EMAIL_PLACEHOLDER_PREG : IsEmail.EMAIL_PREG; + // Trim line start / end anchors off validation regex, make global + let regex = new RegExp(preg.toString().substring(2, preg.toString().length - 3), 'g'); + return value.match(regex); +}