mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2026-09-09 18:02:54 +00:00
[ACS-9374] Prevent library search with search term less than 2 characters
This commit is contained in:
+15
-15
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user