From 010285b219a35f3c16d7c2ab44d41d070bd96b7f Mon Sep 17 00:00:00 2001 From: daniele-pecora Date: Thu, 3 Dec 2020 08:14:32 +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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/projects/schema-form/src/lib/model/formproperty.ts b/projects/schema-form/src/lib/model/formproperty.ts index e31d5681..209f4348 100644 --- a/projects/schema-form/src/lib/model/formproperty.ts +++ b/projects/schema-form/src/lib/model/formproperty.ts @@ -226,6 +226,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, @@ -259,8 +264,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) @@ -272,7 +277,6 @@ export abstract class FormProperty { * @returns `true` if any visibility binding of type `oneOf` or `allOf` has been processed. Otherwise `false`. */ private __bindVisibility_oneOf_or_allOf(): boolean { - /** /** *
      *     "oneOf":[{

From fae29c7daff383e560d1d3303ee101bf60486440 Mon Sep 17 00:00:00 2001
From: daniele-pecora 
Date: Thu, 3 Dec 2020 08:20:40 +0100
Subject: [PATCH 2/3] bumb version 2.4.10

---
 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 9ad3feff..41772ccc 100644
--- a/projects/schema-form/package.json
+++ b/projects/schema-form/package.json
@@ -1,6 +1,6 @@
 {
   "name": "ngx-schema-form",
-  "version": "2.4.9",
+  "version": "2.4.10",
   "repository": {
     "type": "git",
     "url": "git+https://github.com/guillotinaweb/ngx-schema-form"

From cb0c749e7e0a5debd55ef171968cb9458d2548ca Mon Sep 17 00:00:00 2001
From: daniele-pecora 
Date: Thu, 3 Dec 2020 08:26:46 +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 209f4348..c33e8a7e 100644
--- a/projects/schema-form/src/lib/model/formproperty.ts
+++ b/projects/schema-form/src/lib/model/formproperty.ts
@@ -313,7 +313,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
                             }
@@ -327,7 +327,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;
                             }