From 75e1f7612fed0fcc02886b3d8dae250a17f17dd0 Mon Sep 17 00:00:00 2001 From: renczesstefan Date: Mon, 11 May 2026 12:06:19 +0200 Subject: [PATCH 1/3] [NAE-2435] Enumeration field with no choices does not properly handle validation - refactore checkKey function in enumeration-field.ts --- .../enumeration-field/models/enumeration-field.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts b/projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts index afcf8aac7..e0d46a181 100644 --- a/projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts +++ b/projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts @@ -80,8 +80,11 @@ export class EnumerationField extends DataField { } private checkKey(control: AbstractControl): ValidationErrors | null { - if (this._choices === undefined || this._choices.length === 0 || control.value === '' || control.value === undefined) { - return null; + if (control.value === '' || control.value === undefined) { + return null + } + if (this._choices === undefined || this._choices.length === 0) { + return {wrongValue: true}; } return this._choices.find(choice => choice.key === control.value || control.value === null) ? null : {wrongValue: true}; } From e2fd04861619a4d647dbd45d8709a8c628ba6d1d Mon Sep 17 00:00:00 2001 From: renczesstefan Date: Mon, 11 May 2026 14:57:47 +0200 Subject: [PATCH 2/3] [NAE-2435] Enumeration field with no choices does not properly handle validation Ensure that null values are correctly handled in the validation logic of enumeration fields. This prevents unnecessary errors when null is passed as a control value. --- .../enumeration-field/models/enumeration-field.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts b/projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts index e0d46a181..d8dac0f0c 100644 --- a/projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts +++ b/projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts @@ -80,12 +80,12 @@ export class EnumerationField extends DataField { } private checkKey(control: AbstractControl): ValidationErrors | null { - if (control.value === '' || control.value === undefined) { - return null + if (control.value === '' || control.value === undefined || control.value === null) { + return null; } if (this._choices === undefined || this._choices.length === 0) { return {wrongValue: true}; } - return this._choices.find(choice => choice.key === control.value || control.value === null) ? null : {wrongValue: true}; + return this._choices.find(choice => choice.key === control.value) ? null : {wrongValue: true}; } } From 969a6cda5add3caa755a119c7cf788c17deb2be2 Mon Sep 17 00:00:00 2001 From: renczesstefan Date: Mon, 11 May 2026 16:46:20 +0200 Subject: [PATCH 3/3] Refactor validation logic in enumeration field. Replaced `find` with `some` to improve code clarity and intent. The updated method now directly checks for the existence of a matching key, simplifying the logic while maintaining functionality. --- .../data-fields/enumeration-field/models/enumeration-field.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts b/projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts index d8dac0f0c..f1f72035b 100644 --- a/projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts +++ b/projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts @@ -86,6 +86,6 @@ export class EnumerationField extends DataField { if (this._choices === undefined || this._choices.length === 0) { return {wrongValue: true}; } - return this._choices.find(choice => choice.key === control.value) ? null : {wrongValue: true}; + return this._choices.some(choice => choice.key === control.value) ? null : {wrongValue: true}; } }