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', () => {
|
it('should check if searchTerm has a length less than 2', () => {
|
||||||
expect(component.isTermTooShort()).toBe(false);
|
|
||||||
component.searchTerm = 'd';
|
component.searchTerm = 'd';
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(component.isTermTooShort()).toBe(true);
|
expect(component.isTermTooShort()).toBe(true);
|
||||||
|
|||||||
+37
-12
@@ -22,7 +22,20 @@
|
|||||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
* 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 { CommonModule } from '@angular/common';
|
||||||
import { TranslatePipe } from '@ngx-translate/core';
|
import { TranslatePipe } from '@ngx-translate/core';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
@@ -41,9 +54,22 @@ import { noWhitespaceValidator } from '@alfresco/aca-shared';
|
|||||||
encapsulation: ViewEncapsulation.None,
|
encapsulation: ViewEncapsulation.None,
|
||||||
host: { class: 'app-search-control' }
|
host: { class: 'app-search-control' }
|
||||||
})
|
})
|
||||||
export class SearchInputControlComponent implements OnInit {
|
export class SearchInputControlComponent implements OnInit, OnChanges {
|
||||||
private readonly destroyRef = inject(DestroyRef);
|
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). */
|
/** Type of the input field to render, e.g. "search" or "text" (default). */
|
||||||
@Input()
|
@Input()
|
||||||
inputType = 'text';
|
inputType = 'text';
|
||||||
@@ -96,16 +122,7 @@ export class SearchInputControlComponent implements OnInit {
|
|||||||
this.searchFieldFormControl.events.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((event) => {
|
this.searchFieldFormControl.events.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((event) => {
|
||||||
if (event instanceof TouchedChangeEvent || event instanceof StatusChangeEvent) {
|
if (event instanceof TouchedChangeEvent || event instanceof StatusChangeEvent) {
|
||||||
if (this.searchFieldFormControl.touched) {
|
if (this.searchFieldFormControl.touched) {
|
||||||
const errors = this.searchFieldFormControl.errors;
|
this.validateInput();
|
||||||
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('');
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.validationError.emit('');
|
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() {
|
openDropdown() {
|
||||||
this.searchInput.nativeElement.focus();
|
this.searchInput.nativeElement.focus();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -153,8 +153,8 @@ export class SearchInputComponent implements OnInit, OnDestroy {
|
|||||||
showInputValue() {
|
showInputValue() {
|
||||||
this.appService.setAppNavbarMode('collapsed');
|
this.appService.setAppNavbarMode('collapsed');
|
||||||
this.has400LibraryError = false;
|
this.has400LibraryError = false;
|
||||||
this.hasLibrariesConstraint = this.evaluateLibrariesConstraint();
|
|
||||||
this.searchedWord = this.getUrlSearchTerm();
|
this.searchedWord = this.getUrlSearchTerm();
|
||||||
|
this.hasLibrariesConstraint = this.evaluateLibrariesConstraint();
|
||||||
|
|
||||||
if (this.searchInputControl) {
|
if (this.searchInputControl) {
|
||||||
this.searchInputControl.searchTerm = this.searchedWord;
|
this.searchInputControl.searchTerm = this.searchedWord;
|
||||||
@@ -203,8 +203,8 @@ export class SearchInputComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.has400LibraryError = false;
|
this.has400LibraryError = false;
|
||||||
this.hasLibrariesConstraint = this.evaluateLibrariesConstraint();
|
|
||||||
this.searchedWord = searchTerm;
|
this.searchedWord = searchTerm;
|
||||||
|
this.hasLibrariesConstraint = this.evaluateLibrariesConstraint();
|
||||||
}
|
}
|
||||||
|
|
||||||
searchByOption() {
|
searchByOption() {
|
||||||
|
|||||||
Reference in New Issue
Block a user