[ACS-9374] Prevent library search with search term less than 2 characters

This commit is contained in:
Shivangi917
2025-07-28 08:08:48 -04:00
parent 47c68adac9
commit a0aa13a020
2 changed files with 19 additions and 15 deletions
@@ -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('');
}
}
}
@@ -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) {