Skip to content

Commit 424eef4

Browse files
committed
fix min validation check + emptying cards
1 parent e6785d3 commit 424eef4

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-rich-media/input-rich-media.element.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,21 @@ export class UmbInputRichMediaElement extends UmbFormControlMixin<
235235
'valueMissing',
236236
() => this.requiredMessage ?? UMB_VALIDATION_EMPTY_LOCALIZATION_KEY,
237237
() => {
238-
return !this.readonly && (!this.value || this.value.length === 0);
238+
return !this.readonly && !!this.required && (!this.value || this.value.length === 0);
239239
},
240240
);
241241

242242
this.addValidator(
243243
'rangeUnderflow',
244244
() => this.minMessage,
245-
() => !this.readonly && !!this.min && (this.value?.length ?? 0) < this.min,
245+
() =>
246+
!this.readonly &&
247+
// Only if min is set:
248+
!!this.min &&
249+
// if the value is empty and not required, we should not validate the min:
250+
!(this.value?.length === 0 && this.required == false) &&
251+
// Validate the min:
252+
(this.value?.length ?? 0) < this.min,
246253
);
247254
this.addValidator(
248255
'rangeOverflow',
@@ -257,15 +264,16 @@ export class UmbInputRichMediaElement extends UmbFormControlMixin<
257264

258265
async #populateCards() {
259266
const mediaItems = this.#itemManager.getItems();
260-
// Check if all media items is loaded.
261-
// But notice, it would be nicer UX if we could show a loading state on the cards that are missing(loading) their items.
262-
const missingCards = mediaItems.filter((item) => !this._cards.find((card) => card.unique === item.unique));
263-
if (!missingCards.length) return;
264267

265268
if (!mediaItems.length) {
266269
this._cards = [];
267270
return;
268271
}
272+
// Check if all media items is loaded.
273+
// But notice, it would be nicer UX if we could show a loading state on the cards that are missing(loading) their items.
274+
const missingCards = mediaItems.filter((item) => !this._cards.find((card) => card.unique === item.unique));
275+
const removedCards = this._cards.filter((card) => !mediaItems.find((item) => card.unique === item.unique));
276+
if (missingCards.length === 0 && removedCards.length === 0) return;
269277

270278
this._cards =
271279
this.value?.map((item) => {

0 commit comments

Comments
 (0)