mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2026-09-09 18:02:54 +00:00
[ACS-9374] Add validator to aca-shared
This commit is contained in:
+2
-2
@@ -31,7 +31,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { FormControl, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { noWhitespaceValidator } from 'projects/aca-content/folder-rules/src/rule-details/validators/no-whitespace.validator';
|
||||
import { noWhitespaceValidator } from 'projects/aca-shared/src/lib/validators/no-whitespace.validator';
|
||||
|
||||
@Component({
|
||||
imports: [CommonModule, TranslatePipe, MatButtonModule, MatIconModule, MatFormFieldModule, MatInputModule, FormsModule, ReactiveFormsModule],
|
||||
@@ -106,6 +106,6 @@ export class SearchInputControlComponent implements OnInit {
|
||||
}
|
||||
|
||||
isTermTooShort() {
|
||||
return !!(this.searchTerm.trim() && this.searchTerm.trim().length < 2);
|
||||
return this.searchTerm.trim()?.length < 2;
|
||||
}
|
||||
}
|
||||
|
||||
+14
-10
@@ -36,17 +36,21 @@
|
||||
(submit)="onSearchSubmit($event)"
|
||||
(searchChange)="onSearchChange($event)"
|
||||
/>
|
||||
<mat-error *ngIf="hasLibrariesConstraint" class="app-search-error">
|
||||
{{ 'SEARCH.INPUT.HINT' | translate }}
|
||||
<mat-error *ngIf="searchInputControl.searchFieldFormControl.touched" class="app-search-error">
|
||||
<ng-container *ngIf="hasLibrariesConstraint; else checkRequired">
|
||||
{{ 'SEARCH.INPUT.HINT' | translate }}
|
||||
</ng-container>
|
||||
<ng-template #checkRequired>
|
||||
<ng-container *ngIf="searchInputControl.searchFieldFormControl.errors?.required; else checkWhitespace">
|
||||
{{ 'SEARCH.INPUT.REQUIRED' | translate }}
|
||||
</ng-container>
|
||||
</ng-template>
|
||||
<ng-template #checkWhitespace>
|
||||
<ng-container *ngIf="searchInputControl.searchFieldFormControl.errors?.whitespace">
|
||||
{{ 'SEARCH.INPUT.WHITESPACE' | translate }}
|
||||
</ng-container>
|
||||
</ng-template>
|
||||
</mat-error>
|
||||
<mat-error
|
||||
*ngIf="searchInputControl.searchFieldFormControl.errors?.required && searchInputControl.searchFieldFormControl.touched" class="app-search-error">
|
||||
{{ 'SEARCH.INPUT.REQUIRED' | translate }}
|
||||
</mat-error>
|
||||
<mat-error *ngIf="searchInputControl.searchFieldFormControl.errors?.whitespace && searchInputControl.searchFieldFormControl.touched" class="app-search-error">
|
||||
{{ 'SEARCH.INPUT.WHITESPACE' | translate }}
|
||||
</mat-error>
|
||||
|
||||
<div id="search-options" class="app-search-options">
|
||||
<mat-checkbox *ngFor="let option of searchOptions"
|
||||
id="{{ option.id }}"
|
||||
|
||||
+2
-2
@@ -47,13 +47,13 @@ describe('SearchInputComponent', () => {
|
||||
return error?.nativeElement.textContent.trim();
|
||||
}
|
||||
|
||||
async function openMenu() {
|
||||
async function openMenu(): Promise<MatMenuHarness> {
|
||||
const menu = await loader.getHarness(MatMenuHarness);
|
||||
await menu.open();
|
||||
return menu;
|
||||
}
|
||||
|
||||
async function getCheckbox(id: string) {
|
||||
function getCheckbox(id: string): Promise<MatCheckboxHarness> {
|
||||
const overlayLoader = TestbedHarnessEnvironment.documentRootLoader(fixture);
|
||||
return overlayLoader.getHarness(MatCheckboxHarness.with({ selector: `#${id}` }));
|
||||
}
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms';
|
||||
export const noWhitespaceValidator = (): ValidatorFn => {
|
||||
return (control: AbstractControl): ValidationErrors | null => {
|
||||
const rawValue = control.value;
|
||||
if (rawValue === null || rawValue === '') {
|
||||
if (!rawValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user