From 8ac0f63a7ac547ab95df69fcd1f73ea7068e762e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Wed, 28 Aug 2024 13:53:15 +0200 Subject: [PATCH] area validation --- .../block-grid-entries.element.ts | 15 +++++++++++---- .../context/block-grid-entries.context.ts | 8 ++++++-- .../src/packages/block/block-grid/types.ts | 4 ++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/components/block-grid-entries/block-grid-entries.element.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/components/block-grid-entries/block-grid-entries.element.ts index 55ab4b266e..6d9dfb3f18 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/components/block-grid-entries/block-grid-entries.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/components/block-grid-entries/block-grid-entries.element.ts @@ -236,7 +236,6 @@ export class UmbBlockGridEntriesElement extends UmbFormControlMixin(UmbLitElemen #rangeUnderflowValidator?: UmbFormControlValidatorConfig; #rangeOverflowValidator?: UmbFormControlValidatorConfig; async #setupRangeValidation(rangeLimit: UmbNumberRangeValueType | undefined) { - console.log('setupRangeValidation', rangeLimit); if (this.#rangeUnderflowValidator) { this.removeValidator(this.#rangeUnderflowValidator); this.#rangeUnderflowValidator = undefined; @@ -295,14 +294,14 @@ export class UmbBlockGridEntriesElement extends UmbFormControlMixin(UmbLitElemen `, )} - ${this._areaKey ? html` ` : nothing} ${this._canCreate ? this.#renderCreateButton() : nothing} + ${this._areaKey ? html` ` : nothing} `; } #renderCreateButton() { if (this._areaKey === null || this._layoutEntries.length === 0) { - return html` + return html` div { display: flex; flex-direction: column; align-items: stretch; } - uui-button-group { + #createButton { padding-top: 1px; grid-template-columns: 1fr auto; --umb-block-grid--is-dragging--variable: var(--umb-block-grid--is-dragging) none; display: var(--umb-block-grid--is-dragging--variable, grid); } + :host(:not([pristine]):invalid) #createButton { + --uui-button-contrast: var(--uui-color-danger); + --uui-button-contrast-hover: var(--uui-color-danger); + --uui-color-default-emphasis: var(--uui-color-danger); + --uui-button-border-color: var(--uui-color-danger); + --uui-button-border-color-hover: var(--uui-color-danger); + } .umb-block-grid__layout-container[data-area-length='0'] { --umb-block-grid--is-dragging--variable: var(--umb-block-grid--is-dragging) 1; diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/context/block-grid-entries.context.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/context/block-grid-entries.context.ts index 9117cd71c2..a4e93e9d50 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/context/block-grid-entries.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/context/block-grid-entries.context.ts @@ -84,6 +84,10 @@ export class UmbBlockGridEntriesContext this.#workspaceModal.setUniquePathValue('areaKey', areaKey ?? 'null'); this.#catalogueModal.setUniquePathValue('areaKey', areaKey ?? 'null'); this.#gotAreaKey(); + + // Idea: If we need to parse down a validation data path to target the specific layout object: [NL] + // If we have a areaKey, we want to inherit our layoutDataPath from nearest blockGridEntry context. + // If not, we want to set the layoutDataPath to a base one. } setLayoutColumns(columns: number | undefined) { @@ -315,8 +319,8 @@ export class UmbBlockGridEntriesContext if (!this.#areaType) return undefined; // No need to observe as this method is called every time the area is changed. this.#rangeLimits.setValue({ - min: this.#areaType.minAllowed ?? 0, - max: this.#areaType.maxAllowed ?? Infinity, + min: this.#areaType.minAllowed ? parseInt(this.#areaType.minAllowed) : 0, + max: this.#areaType.maxAllowed ? parseInt(this.#areaType.maxAllowed) : Infinity, }); } else if (this.#areaKey === null) { if (!this._manager) return undefined; diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/types.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/types.ts index fa688cfbe4..ec00759eec 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/types.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/types.ts @@ -26,8 +26,8 @@ export interface UmbBlockGridTypeAreaType { alias: string; columnSpan?: number; rowSpan?: number; - minAllowed?: number; - maxAllowed?: number; + minAllowed?: string; + maxAllowed?: string; specifiedAllowance?: Array; }