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
538 stars 154 forks source link

Non-required fields become required after interaction with them #395

Closed mvandenburgh closed 1 year ago

mvandenburgh commented 1 year ago

Given the following (abbreviated) sub-schema for an array of Persons:

"Person": {
  "title": "Person",
  "type": "object",
  "properties": {
    "id": {
      "title": "ID",
      "description": "Uniform resource identifier",
      "readOnly": true,
      "type": "string"
    },
    "schemaKey": {
      "title": "Schema Key",
      "default": "Person",
      "type": "string",
      "const": "Person"
    },
    "name": {
      "title": "Name",
      "description": "Use the format: familyname, given names ...",
      "nskey": "schema",
      "examples": [
        "Lovelace, Augusta Ada",
        "Smith, John",
        "Chan, Kong-sang"
      ],
      "type": "string"
    },
    "email": {
      "title": "Email",
      "nskey": "schema",
      "type": "string",
      "format": "email"
    },
    "url": {
      "title": "URL",
      "nskey": "schema",
      "minLength": 1,
      "maxLength": 1000,
      "format": "uri",
      "type": "string"
    },
    ...
  },
  "required": [
    "name",
    "schemaKey"
  ]
},

Note that the url field is not required. However, if the user starts typing something into the url field and then deletes it, vjsf will report the input as invalid due to the minLength being 1. I don't think this is the correct behavior; since url is not a required field, an empty url input should be valid.

MVCE: https://codepen.io/mvandenburgh/pen/WNjzGdw

GIF reproducing the bug: vjsf

bendichter commented 1 year ago

I would also be interested in a fix for this. Thanks!

albanm commented 1 year ago

A fix similar to this one is probably required : https://github.com/koumoul-dev/vuetify-jsonschema-form/commit/effa0c25cf77371bd4b5a13c3e20ac5e77823d1a

mvandenburgh commented 1 year ago

Thanks for the tip @albanm! I'll look into implementing a fix like that.