From 018a59e001f8ee19b388d702f6a9d8a0e8a37ba0 Mon Sep 17 00:00:00 2001 From: daniele-pecora Date: Thu, 3 Dec 2020 08:15:07 +0100 Subject: [PATCH 1/3] handle non existing fields in visibleIf - oneOf and allOf as null value. fix #370 --- projects/schema-form/src/lib/model/formproperty.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/projects/schema-form/src/lib/model/formproperty.ts b/projects/schema-form/src/lib/model/formproperty.ts index 489ebeaf..e41fb69a 100644 --- a/projects/schema-form/src/lib/model/formproperty.ts +++ b/projects/schema-form/src/lib/model/formproperty.ts @@ -227,6 +227,11 @@ export abstract class FormProperty { /** * Making use of the expression compiler for the visibleIf condition + * @param sourceProperty The source property where the `visibleIf` condition is set. + * @param targetProperty The target property what provided the `value` on which the `visibleIf` condition will be checked against. May be `null` or `undefined` + * @param dependencyPath The dependency path of the `targetProperty` + * @param value The value of the `targetProperty` to check the `visiblityIf` condintion against. May be `null` or `undefined` + * @param expression The value or expression to check against the `value` for the `targetProperty`. May be `null` or `undefined` */ private __evaluateVisibilityIf( sourceProperty: FormProperty, @@ -260,8 +265,8 @@ export abstract class FormProperty { return valid } catch (error) { this.logger.error('Error processing "VisibileIf" expression for path: ', dependencyPath, - `source - ${sourceProperty._canonicalPath}: `, sourceProperty, - `target - ${targetProperty._canonicalPath}: `, targetProperty, + `source - ${(sourceProperty ? sourceProperty._canonicalPath : '')}: `, sourceProperty, + `target - ${(targetProperty ? targetProperty._canonicalPath : '')}: `, targetProperty, 'value:', value, 'expression: ', expression, 'error: ', error) From 09309b07c94a625e6f1ab840351ec7525f4c3f1d Mon Sep 17 00:00:00 2001 From: daniele-pecora Date: Thu, 3 Dec 2020 08:21:46 +0100 Subject: [PATCH 2/3] bump version 2.5.9 --- projects/schema-form/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/schema-form/package.json b/projects/schema-form/package.json index d6abf123..a742c667 100644 --- a/projects/schema-form/package.json +++ b/projects/schema-form/package.json @@ -1,6 +1,6 @@ { "name": "ngx-schema-form", - "version": "2.5.8", + "version": "2.5.9", "repository": { "type": "git", "url": "git+https://github.com/guillotinaweb/ngx-schema-form" From 81c696151796cdc1dbe6f01e80d0ed94191e730f Mon Sep 17 00:00:00 2001 From: daniele-pecora Date: Thu, 3 Dec 2020 08:26:26 +0100 Subject: [PATCH 3/3] set to null if field not present --- projects/schema-form/src/lib/model/formproperty.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/schema-form/src/lib/model/formproperty.ts b/projects/schema-form/src/lib/model/formproperty.ts index e41fb69a..d47bc653 100644 --- a/projects/schema-form/src/lib/model/formproperty.ts +++ b/projects/schema-form/src/lib/model/formproperty.ts @@ -314,7 +314,7 @@ export abstract class FormProperty { for (const item of this.schema.visibleIf.oneOf) { for (const depPath of Object.keys(item)) { const prop = this.searchProperty(depPath); - const propVal = prop.value; + const propVal = prop ? prop.value : null; if (this.__evaluateVisibilityIf(this, prop, dependencyPath, propVal, item[depPath])) { return true } @@ -328,7 +328,7 @@ export abstract class FormProperty { for (const item of this.schema.visibleIf.allOf) { for (const depPath of Object.keys(item)) { const prop = this.searchProperty(depPath); - const propVal = prop.value; + const propVal = prop ? prop.value : null; if (!this.__evaluateVisibilityIf(this, prop, dependencyPath, propVal, item[depPath])) { return false; }