jsonform / jsonform

Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.
https://jsonform.github.io/jsonform/playground/index.html
MIT License
2.72k stars 553 forks source link

form type checkboxes does correctly display, produces no results on submit #418

Closed sdetweil closed 2 weeks ago

sdetweil commented 1 year ago

i am trying to enhance lib to support scrollable checkboxes..

so I built this form

  {
  "schema": {
          "name": {
            "type": "object",
           "properties":{
              "list":{
                "type:": "string",
                "enum": [
                  "one",
                  "two",
                  "four",
                  "ten"
               ]
             },
             "fribble":{
                "type": "string",
                "enum": [
                  "six",
                  "seven",
                  "eight",
                  "nine"
               ]
             }
           }
          }
        },
        "form":[
           {
            "title": "Settings",
            "type": "fieldset",
            "expandable": false,
            "order": 0,
            "items": [
                {
                  "key":"name.list",
                  "type": "checkboxes",
                  "scrollable": true,
                  "height":5
                },
                {
                  "key": "name.fribble",
                  "type": "checkboxes"
                }
            ]
          },
          {
            "type": "submit",
            "title": "Submit",
            "id": "submit_button"
          }
        ],
        "value":{
             "name":{
              "list": ["one","ten"],
              "fribble":["seven"]
             }
        }
      }         

get the right presentation but on submit, I get no results.. (in playground) Screenshot at 2022-09-17 17-08-26

sdetweil commented 1 year ago

if I change the sample in a similar way, (no array, but property in an object) , I get no results..

{
  "schema": {
    "menu": {
      "type":"object",
        "properties": {
          "option":{
            "type": "string",
            "title": "Option",
            "enum": [
              "starter",
              "maincourse",
              "cheese",
              "dessert"
            ]
          }
      }
    }
  },
  "form": [
    {
      "key": "menu.option",
      "type": "checkboxes",
      "titleMap": {
        "starter": "Starter would be great",
        "maincourse": "No way I'll skip the main course",
        "cheese": "Cheddar rules!",
        "dessert": "Thumbs up for a dessert"
      }
    },
          {
            "type": "submit",
            "title": "Submit",
            "id": "submit_button"
          }
  ]
}
sdetweil commented 1 year ago

so, this is a bug in the validation , when using checkboxes in the form (it also sneaks in in the schema)

the doc says

https://github.com/jsonform/jsonform/wiki#multiple-options-the-checkboxes-type

Multiple options: the checkboxes type If you need the user to select one or more options among a list of choices, the checkboxes form field is for your. _It applies to an array property whose items_ schema explicitly defines a list of possible values in an enum property.

there is a separate bug in the doc, above, which says

the checkboxes form field is for your.

should be

the checkboxes form field is for you.

wiki fixed (sept 18,2022)