From a0aa13a020b7f66b19091efc6f5e1d73503c4ae6 Mon Sep 17 00:00:00 2001 From: Shivangi917 Date: Thu, 24 Jul 2025 10:14:14 -0400 Subject: [PATCH] [ACS-9374] Prevent library search with search term less than 2 characters --- .../search-input-control.component.ts | 30 +++++++++---------- .../search-input/search-input.component.ts | 4 +++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.ts b/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.ts index 708cd32b1..5aa4980a9 100644 --- a/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.ts +++ b/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.ts @@ -57,19 +57,6 @@ import { noWhitespaceValidator } from '@alfresco/aca-shared'; export class SearchInputControlComponent implements OnInit, OnChanges { private readonly destroyRef = inject(DestroyRef); - private validateInput(): void { - const errors = this.searchFieldFormControl.errors; - if (errors?.whitespace) { - this.validationError.emit('SEARCH.INPUT.WHITESPACE'); - } else if (errors?.required) { - this.validationError.emit('SEARCH.INPUT.REQUIRED'); - } else if (this.hasLibrariesConstraint && this.isTermTooShort()) { - this.validationError.emit('SEARCH.INPUT.MIN_LENGTH'); - } else { - this.validationError.emit(''); - } - } - /** Type of the input field to render, e.g. "search" or "text" (default). */ @Input() inputType = 'text'; @@ -122,7 +109,7 @@ export class SearchInputControlComponent implements OnInit, OnChanges { this.searchFieldFormControl.events.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((event) => { if (event instanceof TouchedChangeEvent || event instanceof StatusChangeEvent) { if (this.searchFieldFormControl.touched) { - this.validateInput(); + this.emitValidationError(); } else { this.validationError.emit(''); } @@ -132,7 +119,7 @@ export class SearchInputControlComponent implements OnInit, OnChanges { ngOnChanges(changes: SimpleChanges): void { if (changes['hasLibrariesConstraint'] && !changes['hasLibrariesConstraint'].firstChange && this.searchFieldFormControl.touched) { - this.validateInput(); + this.emitValidationError(); } } @@ -161,4 +148,17 @@ export class SearchInputControlComponent implements OnInit, OnChanges { isTermTooShort() { return this.searchTerm.trim()?.length < 2; } + + private emitValidationError(): void { + const errors = this.searchFieldFormControl.errors; + if (errors?.whitespace) { + this.validationError.emit('SEARCH.INPUT.WHITESPACE'); + } else if (errors?.required) { + this.validationError.emit('SEARCH.INPUT.REQUIRED'); + } else if (this.hasLibrariesConstraint && this.isTermTooShort()) { + this.validationError.emit('SEARCH.INPUT.MIN_LENGTH'); + } else { + this.validationError.emit(''); + } + } } diff --git a/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts b/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts index 9099b751e..87c37f281 100644 --- a/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts +++ b/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts @@ -217,6 +217,10 @@ export class SearchInputComponent implements OnInit, OnDestroy { if (this.isLibrariesChecked()) { this.hasLibrariesConstraint = this.evaluateLibrariesConstraint(); + + if (this.hasLibrariesConstraint) { + return; + } if (this.onLibrariesSearchResults && this.isSameSearchTerm()) { this.queryLibrariesBuilder.update(); } else if (this.searchedWord) {