diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/components/input-entity/input-entity.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/components/input-entity/input-entity.element.ts index e99a924bea..9395d4ad09 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/components/input-entity/input-entity.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/components/input-entity/input-entity.element.ts @@ -16,6 +16,8 @@ import type { UmbPickerInputContext } from '@umbraco-cms/backoffice/picker-input @customElement('umb-input-entity') export class UmbInputEntityElement extends FormControlMixin(UmbLitElement) { + // TODO: [LK] Add sort ordering. + protected getFormElement() { return undefined; } @@ -42,6 +44,9 @@ export class UmbInputEntityElement extends FormControlMixin(UmbLitElement) { return this.#pickerContext?.max ?? Infinity; } + @property({ attribute: false }) + getIcon?: (item: any) => string; + @property({ type: String, attribute: 'min-message' }) maxMessage = 'This field exceeds the allowed amount of items'; @@ -53,14 +58,12 @@ export class UmbInputEntityElement extends FormControlMixin(UmbLitElement) { return this.selection?.join(',') ?? ''; } + @property({ attribute: false }) public set pickerContext(ctor: new (host: UmbControllerHost) => UmbPickerInputContext) { if (this.#pickerContext) return; this.#pickerContext = new ctor(this); this.#observePickerContext(); } - public get pickerContext(): UmbPickerInputContext | undefined { - return this.#pickerContext; - } #pickerContext?: UmbPickerInputContext; public set selection(value: Array) { @@ -78,23 +81,23 @@ export class UmbInputEntityElement extends FormControlMixin(UmbLitElement) { super(); } - // connectedCallback() { - // super.connectedCallback(); + connectedCallback() { + super.connectedCallback(); - // if (!this.#pickerContext) return; + if (!this.#pickerContext) return; - // this.addValidator( - // 'rangeUnderflow', - // () => this.minMessage, - // () => !!this.min && this.#pickerContext.getSelection().length < this.min, - // ); + this.addValidator( + 'rangeUnderflow', + () => this.minMessage, + () => !!this.min && (this.#pickerContext?.getSelection().length ?? 0) < this.min, + ); - // this.addValidator( - // 'rangeOverflow', - // () => this.maxMessage, - // () => !!this.max && this.#pickerContext.getSelection().length > this.max, - // ); - // } + this.addValidator( + 'rangeOverflow', + () => this.maxMessage, + () => !!this.max && (this.#pickerContext?.getSelection().length ?? 0) > this.max, + ); + } async #observePickerContext() { if (!this.#pickerContext) return; @@ -121,7 +124,7 @@ export class UmbInputEntityElement extends FormControlMixin(UmbLitElement) { } render() { - return html` ${this.#renderItems()} ${this.#renderAddButton()} `; + return html`${this.#renderItems()} ${this.#renderAddButton()}`; } #renderAddButton() { @@ -150,9 +153,10 @@ export class UmbInputEntityElement extends FormControlMixin(UmbLitElement) { #renderItem(item: any) { if (!item.unique) return; + const icon = this.getIcon?.(item) ?? item.icon; return html` - ${when(item.icon, () => html``)} + ${when(icon, () => html``)} this.#pickerContext?.requestRemoveItem(item.unique)}