jsonforms icon indicating copy to clipboard operation
jsonforms copied to clipboard

rule not validated when property is not present at all

Open flx-sta opened this issue 4 years ago • 1 comments

Describe the bug rules with the schema {const: null} don't validate successfully when the respective property doesn't exist

To Reproduce Steps to reproduce the behavior:

  1. check out this repo on the specific branch: https://github.com/Felix-Puetz/jsonforms-vue-example/tree/bug/const-null-returns-true-on-empty-object
  2. run npm install in it
  3. run npm run serve in it
  4. launch the given url in your browser

Example schema:

{
  type: "object",
  properties: {
    name: { type: "string" },
    mail: { type: "string" },
  },
  required: ["name", "mail"],
};

Example uischema:

{
  type: "VerticalLayout",
  elements: [
    {
      scope: "#/properties/name",
      type: "control",
    },
    {
      scope: "#/properties/mail",
      type: "control",
      rule: {
        condition: {
          scope: "#/properties/name",
          schema: {
              const: null
          },
        },
        effect: "DISABLE",
      },
    },
  ]
}

Expected behavior mail field should be disabled when name is not present in data

Screenshots

image

Browser (please complete the following information):

  • Browser all (latest release)

Used Setup (please complete the following information): All info present in my repository

Additional context spoke to @sdirix and he confirmed

flx-sta avatar Feb 03 '21 11:02 flx-sta

I would have expected the ui schema to work. It actually works when moving the scope of the rule one level up:

    {
      scope: "#/properties/mail",
      type: "control",
      rule: {
        condition: {
          scope: "#",
          schema: {
            properties: {
              name: {
                const: null
              }
            },
          },
        },
        effect: "DISABLE",
      },
    },

We need to investigate whether this is a bug, according to spec, or some implementation defined behavior which we can adjust.

sdirix avatar Feb 03 '21 12:02 sdirix