fixing bug on default autocomplete-input validation mechanism

This commit is contained in:
Maria Teresa Paratore 2023-11-15 17:59:53 +01:00
parent 2548bcfd63
commit bc5a3e8c6a
2 changed files with 32 additions and 6 deletions

View File

@ -22,6 +22,7 @@
<span id="home-logged-message" *ngIf="account" jhiTranslate="home.logged.message" <span id="home-logged-message" *ngIf="account" jhiTranslate="home.logged.message"
[translateValues]="{ username: account.login }">You are logged in as user "{{account.login}}".</span> [translateValues]="{ username: account.login }">You are logged in as user "{{account.login}}".</span>
</div> </div>
<!--
<div class="d-inline-block my-3"> <div class="d-inline-block my-3">
<mat-form-field> <mat-form-field>
<mat-label>Your Contexts</mat-label> <mat-label>Your Contexts</mat-label>
@ -31,8 +32,9 @@
</mat-option> </mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
</div> </div>
-->
<div> <div>
<div class="d-inline-block my-3" ngbDropdown #myDrop="ngbDropdown" ></div> <div class="d-inline-block my-3" ngbDropdown #myDrop="ngbDropdown" ></div>

View File

@ -22,6 +22,7 @@ import { IContextNode } from 'app/services/i-context-node';
styleUrls: ['./home.component.scss'], styleUrls: ['./home.component.scss'],
providers: [ContextsLoaderService], providers: [ContextsLoaderService],
}) })
export class HomeComponent implements OnInit { export class HomeComponent implements OnInit {
account: Account | null = null; account: Account | null = null;
@ -32,8 +33,6 @@ export class HomeComponent implements OnInit {
chooseContextForm: FormGroup | any; chooseContextForm: FormGroup | any;
resType: string; resType: string;
constructor( constructor(
private accountService: AccountService, private accountService: AccountService,
private loginService: LoginService, private loginService: LoginService,
@ -84,12 +83,23 @@ export class HomeComponent implements OnInit {
//PER VALIDAZIONE FORM //PER VALIDAZIONE FORM
/*
checkForErrorsIn(formControl: AbstractControl): string { checkForErrorsIn(formControl: AbstractControl): string {
if (formControl.hasError('required')) { if (formControl.hasError('required')) {
return 'Value is required!'; return 'Value is required!';
} }
return ''; 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 { displayFn(ctx: IContextNode): string {
@ -98,6 +108,16 @@ export class HomeComponent implements OnInit {
} }
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 { displayFn(ctx: string): string {
const tmp = ctx ? ctx + ' (poi ci va id) ': ''; const tmp = ctx ? ctx + ' (poi ci va id) ': '';
@ -105,6 +125,8 @@ export class HomeComponent implements OnInit {
return tmp; return tmp;
} }
*/ */
/*
getContexts(): string[] { getContexts(): string[] {
if (this.account != null && this.account.resourceAccessDTO != null) { if (this.account != null && this.account.resourceAccessDTO != null) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
@ -120,6 +142,8 @@ export class HomeComponent implements OnInit {
return []; return [];
} }
} }
*/
copyUid(val: any): void { copyUid(val: any): void {
if (val instanceof FormControl) { if (val instanceof FormControl) {