Fixed dropdown/lookup & lookup-name fields being reset when hitting enter (#3724)

This commit is contained in:
Alexandre Vryghem
2025-01-03 07:09:44 +01:00
committed by GitHub
parent 08f48d8204
commit 2cde0d3f21
3 changed files with 12 additions and 6 deletions

View File

@@ -94,11 +94,12 @@
(scrolled)="onScroll()" (scrolled)="onScroll()"
[scrollWindow]="false"> [scrollWindow]="false">
<button class="dropdown-item disabled" <button class="dropdown-item disabled" type="button"
*ngIf="optionsList && optionsList.length === 0" *ngIf="optionsList && optionsList.length === 0"
(click)="$event.stopPropagation(); clearFields(); sdRef.close();">{{'form.no-results' | translate}} (click)="$event.stopPropagation(); clearFields(); sdRef.close();">
{{ 'form.no-results' | translate }}
</button> </button>
<button class="dropdown-item lookup-item" <button class="dropdown-item lookup-item" type="button"
*ngFor="let listEntry of optionsList" *ngFor="let listEntry of optionsList"
(click)="$event.stopPropagation(); onSelect(listEntry); sdRef.close();" (click)="$event.stopPropagation(); onSelect(listEntry); sdRef.close();"
title="{{ listEntry.display }}"> title="{{ listEntry.display }}">

View File

@@ -40,17 +40,19 @@
(scrolled)="onScroll()" (scrolled)="onScroll()"
[scrollWindow]="false"> [scrollWindow]="false">
<button class="dropdown-item disabled" *ngIf="optionsList && optionsList.length === 0">{{'form.no-results' | translate}}</button> <button class="dropdown-item disabled" type="button" *ngIf="optionsList && optionsList.length === 0">
{{ 'form.no-results' | translate }}
</button>
<button class="dropdown-item collection-item text-truncate" <button class="dropdown-item collection-item text-truncate"
(click)="onSelect(undefined); sdRef.close()" (mousedown)="onSelect(undefined); sdRef.close()" (click)="onSelect(undefined); sdRef.close()" (mousedown)="onSelect(undefined); sdRef.close()"
title="{{ 'dropdown.clear.tooltip' | translate }}" role="option" title="{{ 'dropdown.clear.tooltip' | translate }}" role="option"
> type="button">
<i>{{ 'dropdown.clear' | translate }}</i> <i>{{ 'dropdown.clear' | translate }}</i>
</button> </button>
<button class="dropdown-item collection-item text-truncate" *ngFor="let listEntry of optionsList; let i = index" <button class="dropdown-item collection-item text-truncate" *ngFor="let listEntry of optionsList; let i = index"
[class.active]="i === selectedIndex" [class.active]="i === selectedIndex"
(keydown.enter)="onSelect(listEntry); sdRef.close()" (mousedown)="onSelect(listEntry); sdRef.close()" (keydown.enter)="onSelect(listEntry); sdRef.close()" (mousedown)="onSelect(listEntry); sdRef.close()"
title="{{ listEntry.display }}" role="option" title="{{ listEntry.display }}" role="option" type="button"
[attr.id]="listEntry.display === (currentValue|async) ? ('combobox_' + id + '_selected') : null"> [attr.id]="listEntry.display === (currentValue|async) ? ('combobox_' + id + '_selected') : null">
{{inputFormatter(listEntry)}} {{inputFormatter(listEntry)}}
</button> </button>

View File

@@ -153,6 +153,9 @@ export class FormService {
} }
public addControlErrors(field: AbstractControl, formId: string, fieldId: string, fieldIndex: number) { public addControlErrors(field: AbstractControl, formId: string, fieldId: string, fieldIndex: number) {
if (field.errors === null) {
return;
}
const errors: string[] = Object.keys(field.errors) const errors: string[] = Object.keys(field.errors)
.filter((errorKey) => field.errors[errorKey] === true) .filter((errorKey) => field.errors[errorKey] === true)
.map((errorKey) => `error.validation.${errorKey}`); .map((errorKey) => `error.validation.${errorKey}`);