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

Error when a control is clearable #439

Open boutils opened 3 weeks ago

boutils commented 3 weeks ago

Helo,

I am trying to make a simple selector "clearable". So I tried to add to my schema the following line: "layout": { "props": { "clearable": true } }.

So my spec is something like:

{
  "type": "object",
  "properties": {
    "enum": {
      "type": "string",
      "title": "An enum",
      "enum": [ "value1","value2"],
      "layout": { "props": { "clearable": true } }
    }
  }
}

I expect something working smoothly but it is not the case. If I select a value and remove the value (by clicking on the clear icon), I got the following error (must be a string): Screenshot 2024-06-07 at 07 55 49

Is it really expected? Note that this field is not marked as required in the schema.

As a workaround, I have to use the following spec (type accepts "null" and I added the null value in enum ):

{
  "type": "object",
  "properties": {
    "enum": {
      "type": ["string", "null"],
      "title": "An enum",
      "enum": [ "value1","value2", null],
      "layout": { "props": { "clearable": true } }
    }
  }
}

Even if this workaround is working, I end up with a selector which contains a null entry and so is not slick. Screenshot 2024-06-07 at 08 02 57

Is it possible to simply support this simple schema without errors?

{
  "type": "object",
  "properties": {
    "enum": {
      "type": "string",
      "title": "An enum",
      "enum": [ "value1","value2"],
      "layout": { "props": { "clearable": true } }
    }
  }
}

Otherwise, someone has maybe a better workaround.

Thank you for your help!