1

I have a schema with conditional properties. In the example I'm posting you can see two boolean properties with a conditional textinput property each. I would like to show the textInput just below the boolean that activates it, but as it is now the textInputs appears after the two conditionals.

I've tried grouping by objects but I don't want to show the title that appears in the beggining of each group.

{
  "description": "Test conditionals",
  "title": "Test conditionals",
  "type": "object",
  "properties": {
    "firstConditional": {
      "title": "First conditional",
      "type": "boolean"
    },
    "secondConditional": {
      "title": "Second conditional",
      "type": "boolean"
    }
  },
  "dependencies": {
    "firstConditional": {
      "oneOf": [
        {
          "properties": {
            "firstConditional": {
              "type": "boolean",
              "const": false
            }
          }
        },
        {
          "properties": {
            "firstConditional": {
              "type": "boolean",
              "const": true
            },
            "firstCondInput": {
              "title": "Write here something for first conditional",
              "type": "string"
            }
          }
        }
      ]
    },
    "secondConditional": {
      "oneOf": [
        {
          "properties": {
            "secondConditional": {
              "type": "boolean",
              "const": false
            }
          }
        },
        {
          "properties": {
            "secondConditional": {
              "type": "boolean",
              "const": true
            },
            "secondCondInput": {
              "title": "Write here something for second condition",
              "type": "string"
            }
          }
        }
      ]
    }
  }
}

I expect to have the textInput conditional just below the boolean that enables it.

Is there any way to "order" the visible properties with no need of use group of objects?

Thanks in advance.

  • See: https://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order – Harun Yilmaz Sep 12 '19 at 13:55
  • So from that post I understand that it is not possible to order the properties in a JSON schema, isn't it? – spidermember Sep 12 '19 at 14:14
  • JSON objects are by nature unordered according to the specification. Arrays are ordered. You should not rely on the order of key value pairs in JSON objects. As such, JSON Schema does not and will not support this. – Relequestual Sep 12 '19 at 20:42

1 Answers1

1

I found the solution of that need I had. In this image you can see the result of the JSONschema form posted above:

non ordered JSONschema form

Ordering it is as simple as using the property "ui:order" in the UIschema JSON. So, for this UIschema:

{
   "ui:order": ["firstConditional","firstCondInput","secondConditional","*"]
}

And the result is this:

Ordered form