mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2026-09-09 18:02:54 +00:00
[ACS-9374] Fix error validation process
This commit is contained in:
-1
@@ -80,7 +80,6 @@ describe('SearchInputControlComponent', () => {
|
||||
});
|
||||
|
||||
it('should check if searchTerm has a length less than 2', () => {
|
||||
expect(component.isTermTooShort()).toBe(false);
|
||||
component.searchTerm = 'd';
|
||||
fixture.detectChanges();
|
||||
expect(component.isTermTooShort()).toBe(true);
|
||||
|
||||
+37
-12
@@ -22,7 +22,20 @@
|
||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Component, EventEmitter, Input, Output, ViewEncapsulation, ViewChild, ElementRef, OnInit, inject, DestroyRef } from '@angular/core';
|
||||
import {
|
||||
Component,
|
||||
EventEmitter,
|
||||
Input,
|
||||
Output,
|
||||
ViewEncapsulation,
|
||||
ViewChild,
|
||||
ElementRef,
|
||||
OnInit,
|
||||
inject,
|
||||
DestroyRef,
|
||||
OnChanges,
|
||||
SimpleChanges
|
||||
} from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { TranslatePipe } from '@ngx-translate/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
@@ -41,9 +54,22 @@ import { noWhitespaceValidator } from '@alfresco/aca-shared';
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
host: { class: 'app-search-control' }
|
||||
})
|
||||
export class SearchInputControlComponent implements OnInit {
|
||||
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';
|
||||
@@ -96,16 +122,7 @@ export class SearchInputControlComponent implements OnInit {
|
||||
this.searchFieldFormControl.events.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((event) => {
|
||||
if (event instanceof TouchedChangeEvent || event instanceof StatusChangeEvent) {
|
||||
if (this.searchFieldFormControl.touched) {
|
||||
const errors = this.searchFieldFormControl.errors;
|
||||
if (errors?.whitespace) {
|
||||
this.validationError.emit('SEARCH.INPUT.WHITESPACE');
|
||||
} else if (this.hasLibrariesConstraint) {
|
||||
this.validationError.emit('SEARCH.INPUT.MIN_LENGTH');
|
||||
} else if (errors?.required) {
|
||||
this.validationError.emit('SEARCH.INPUT.REQUIRED');
|
||||
} else {
|
||||
this.validationError.emit('');
|
||||
}
|
||||
this.validateInput();
|
||||
} else {
|
||||
this.validationError.emit('');
|
||||
}
|
||||
@@ -113,6 +130,14 @@ export class SearchInputControlComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['hasLibrariesConstraint'] && !changes['hasLibrariesConstraint'].firstChange) {
|
||||
if (this.searchFieldFormControl.touched) {
|
||||
this.validateInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
openDropdown() {
|
||||
this.searchInput.nativeElement.focus();
|
||||
}
|
||||
|
||||
+2
-2
@@ -153,8 +153,8 @@ export class SearchInputComponent implements OnInit, OnDestroy {
|
||||
showInputValue() {
|
||||
this.appService.setAppNavbarMode('collapsed');
|
||||
this.has400LibraryError = false;
|
||||
this.hasLibrariesConstraint = this.evaluateLibrariesConstraint();
|
||||
this.searchedWord = this.getUrlSearchTerm();
|
||||
this.hasLibrariesConstraint = this.evaluateLibrariesConstraint();
|
||||
|
||||
if (this.searchInputControl) {
|
||||
this.searchInputControl.searchTerm = this.searchedWord;
|
||||
@@ -203,8 +203,8 @@ export class SearchInputComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
this.has400LibraryError = false;
|
||||
this.hasLibrariesConstraint = this.evaluateLibrariesConstraint();
|
||||
this.searchedWord = searchTerm;
|
||||
this.hasLibrariesConstraint = this.evaluateLibrariesConstraint();
|
||||
}
|
||||
|
||||
searchByOption() {
|
||||
|
||||
Reference in New Issue
Block a user