From bc5a3e8c6adf52fb7cdf25fc06fe550a698ef257 Mon Sep 17 00:00:00 2001 From: mariateresa Date: Wed, 15 Nov 2023 17:59:53 +0100 Subject: [PATCH] fixing bug on default autocomplete-input validation mechanism --- src/main/webapp/app/home/home.component.html | 4 ++- src/main/webapp/app/home/home.component.ts | 34 +++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/main/webapp/app/home/home.component.html b/src/main/webapp/app/home/home.component.html index da1ba0a..c72f0ff 100644 --- a/src/main/webapp/app/home/home.component.html +++ b/src/main/webapp/app/home/home.component.html @@ -22,6 +22,7 @@ You are logged in as user "{{account.login}}". + +
diff --git a/src/main/webapp/app/home/home.component.ts b/src/main/webapp/app/home/home.component.ts index 4740f06..58753ec 100644 --- a/src/main/webapp/app/home/home.component.ts +++ b/src/main/webapp/app/home/home.component.ts @@ -22,6 +22,7 @@ import { IContextNode } from 'app/services/i-context-node'; styleUrls: ['./home.component.scss'], providers: [ContextsLoaderService], }) + export class HomeComponent implements OnInit { account: Account | null = null; @@ -31,8 +32,6 @@ export class HomeComponent implements OnInit { //public filteredContextsStr: Observable| undefined; chooseContextForm: FormGroup | any; resType: string; - - constructor( private accountService: AccountService, @@ -84,20 +83,41 @@ export class HomeComponent implements OnInit { //PER VALIDAZIONE FORM + /* checkForErrorsIn(formControl: AbstractControl): string { if (formControl.hasError('required')) { return 'Value is required!'; } return ''; } - - + */ + checkForErrorsIn(formControl: AbstractControl): string { + if (formControl.hasError('')) { + return 'Value is required!'; + } + return ''; + } + + // ValidationErrors | null =>!instanceOfContext(formControl?.value) ? { matchRequired: true } : null; + + + displayFn(ctx: IContextNode): string { //return ctx.name ? ctx.name + ' | ' + ctx.id : ''; return ctx.name; } - + + instanceOfContextFn(context: any): context is IContextNode { + console.debug("*** In instanceOfContext: typeof_context: "+typeof context); + return !!context // truthy + && typeof context !== 'string' // Not just string input in the autocomplete + && 'name' in context; // Has some qualifying property of context type +} + + + + /* displayFn(ctx: string): string { const tmp = ctx ? ctx + ' (poi ci va id) ': ''; @@ -105,6 +125,8 @@ export class HomeComponent implements OnInit { return tmp; } */ + +/* getContexts(): string[] { if (this.account != null && this.account.resourceAccessDTO != null) { // eslint-disable-next-line no-console @@ -120,6 +142,8 @@ export class HomeComponent implements OnInit { return []; } } +*/ + copyUid(val: any): void { if (val instanceof FormControl) {