koumoul-dev / vuetify-jsonschema-form

Create beautiful and low-effort forms that output valid data. Published on npm as @koumoul/vjsf.
https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/
MIT License
539 stars 154 forks source link

readOnly and field props ignored on const type #229

Closed MOHACGCG closed 3 years ago

MOHACGCG commented 3 years ago

Hello and thanks for the great library and documentation!

when using oneOf with const, the properties passed to the const are ignored.

use-case: set the one of condition based on an existing model and not allow people to change it.

example:

{
      "x-display": "expansion-panels",
      "x-options": {
        "dialogProps": {},
        "editMode": "inline"
      },
      "type": "object",
      "properties": {
        "stringField": {
          "title": "ready only works for me!",
          "readOnly": true,
          "x-props": {
            "outlined": true
          },
          "type": "string"
        }
      },
      "oneOf": [
        {
          "properties": {
            "enumField": {
              "title": "read only doesnt work for me :/",
              "readOnly": true,
              "x-props": {
                "outlined": true
              },
              "const": "VAL_1"
            }
          },
          "if": {
            "properties": {
              "enumField": {
                "const": "VAL_1"
              }
            }
          },
          "then": {
            "properties": {
              "config": {
                "$ref": "#/$defs/InnerClass"
              }
            }
          }
        },
        {
          "properties": {
            "enumField": {
              "title": "read only doesnt work for me :/",
              "readOnly": true,
              "x-props": {
                "outlined": true
              },
              "const": "VAL_2"
            }
          },
          "if": {
            "properties": {
              "enumField": {
                "const": "VAL_2"
              }
            }
          },
          "then": {
            "properties": {
              "config": {
                "$ref": "#/$defs/OtherInnerClass"
              }
            }
          }
        }
      ],
      "$defs": {
        "InnerClass": {
          "x-options": {
            "dialogProps": {},
            "editMode": "inline"
          },
          "type": "object",
          "properties": {
            "innerBoolField": {
              "title": "a boolean",
              "x-props": {
                "outlined": true
              },
              "type": "boolean",
              "default": false,
              "x-display": "checkbox"
            }
          },
        },
        "OtherInnerClass": {
          "x-options": {
            "dialogProps": {},
            "editMode": "inline"
          },
          "type": "object",
          "properties": {
            "innerNumberField": {
              "title": "a number",
              "x-props": {
                "outlined": true
              },
              "type": "number"
            }
          },
        }
      }
    }
albanm commented 3 years ago

I agree that this woulld be logical. But I don't know when I will have time to work on it.

albanm commented 3 years ago

I ended up doing it straight away as it was a very easy fix. Available in 1.25.0-beta.5

MOHACGCG commented 3 years ago

nice. thank you!!!

AmareshKulkarni commented 2 years ago

Looks like "x-options" is also ignored. I am using ^2.0.3. If this is just an oversight, could you also fix this please? Thank you!