diff --git a/api/js/etemplate/Et2Link/Et2Link.ts b/api/js/etemplate/Et2Link/Et2Link.ts index 78e608ceb1..9016aed435 100644 --- a/api/js/etemplate/Et2Link/Et2Link.ts +++ b/api/js/etemplate/Et2Link/Et2Link.ts @@ -110,7 +110,7 @@ export class Et2Link extends ExposeMixin(Et2Widget(LitElement)) imple } } - private static MISSING_TITLE = "??"; + static MISSING_TITLE = "??"; // Title is read-only inside private _title : string; diff --git a/api/js/etemplate/Et2Link/Et2LinkEntry.ts b/api/js/etemplate/Et2Link/Et2LinkEntry.ts index 7c5b15a605..6c023d5144 100644 --- a/api/js/etemplate/Et2Link/Et2LinkEntry.ts +++ b/api/js/etemplate/Et2Link/Et2LinkEntry.ts @@ -82,7 +82,6 @@ export class Et2LinkEntry extends Et2InputWidget(FormControlMixin(ValidateMixin( if (this.__value && typeof this.__value === 'object') { select.app = this.__value.app; - select.select_options = [{value: this.__value.id, label: this.__value.title}]; select.value = this.__value.id; } else diff --git a/api/js/etemplate/Et2Link/Et2LinkSearch.ts b/api/js/etemplate/Et2Link/Et2LinkSearch.ts index b5101f6edf..c8b48109ae 100644 --- a/api/js/etemplate/Et2Link/Et2LinkSearch.ts +++ b/api/js/etemplate/Et2Link/Et2LinkSearch.ts @@ -10,6 +10,7 @@ import {css} from "@lion/core"; import {Et2Select} from "../Et2Select/Et2Select"; import {Et2LinkAppSelect} from "./Et2LinkAppSelect"; +import {Et2Link} from "./Et2Link"; export class Et2LinkSearch extends Et2Select { @@ -67,6 +68,45 @@ export class Et2LinkSearch extends Et2Select this.processRemoteResults(result); }); } + + updated(changedProperties) + { + super.updated(changedProperties); + + // Set a value we don't have as an option? That's OK, we'll just add it + if(changedProperties.has("value") && this.value && ( + this.menuItems && this.menuItems.length == 0 || + this.menuItems?.filter && this.menuItems.filter(item => this.value.includes(item.value)).length == 0 + )) + { + this._missingOption(this.value) + } + } + + /** + * The set value requires an option we don't have. + * Add it in, asking server for title if needed + * + * @param value + * @protected + */ + protected _missingOption(value : string) + { + let option = { + value: value, + label: Et2Link.MISSING_TITLE, + class: "loading" + } + // Weird call instead of just unshift() to make sure to trigger setter + this.select_options = Object.assign([option], this.__select_options); + this.egw()?.link_title(this.app, option.value, true).then(title => + { + option.label = title; + option.class = ""; + // It's probably already been rendered + this.requestUpdate(); + }); + } } // @ts-ignore TypeScript is not recognizing that this widget is a LitElement