guillotinaweb / ngx-schema-form

HTML form generation based on JSON Schema
MIT License
485 stars 174 forks source link

Visible if behavior not consistent with paths in oneOf and allOf #389

Closed bennmapes closed 3 years ago

bennmapes commented 3 years ago

As I was working more with the visibleIf's I noticed there was a difference in behavior between how its handled normally and how its handled inside the oneOf's and allOf's.

For example the following visibleIf's should be equivalent:

"visibleIfTest": {
    "type":"string",
    "title": "Visible If catagory has dog selected",
    "default":"Dog selected",
    "visibleIf": {
        "categories/*":["dog"]
    }
},
"visibleIfTest": {
    "type":"string",
    "title": "Visible If catagory has dog selected",
    "default":"Dog selected",
    "visibleIf": {
        "oneOf": [
            {
                "categories/*":["dog"]
            }
        ]
    }
},

But for some reason if the key with the path doesn't start with a / it wont work with a oneOf/allOf but it will normally.

Digging into the same code as my previous issue I found this was fixed when just using findProperties function and going through the properties as opposed to using findPropertyPaths and then searchProperty on each path found.

I'm not sure exactly why these two methods of going about getting the properties produce different results but if there are no drawback to using this first approach for consistency I'll be adding a PR to this issue.