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

Datalist for input fields #410

Closed boeckers closed 1 year ago

boeckers commented 1 year ago

Now supports autocomplete for input fields via datalists.

Previously, this was only possible by some dirty workaround like e.g.

{
  "schema": {
    "city": {
      "type": "string",
      "title": "City"
    }
  },
  "form": [
    {
      "key": "city",
      "fieldHtmlClass": "'list=cityname name='city'",
      "append": "<datalist id='cityname'><option value='Bochum'><option value='Berlin'></datalist>"
    }
  ]
}

Now, the same behaviour can be achieved by

{
  "schema": {
    "city": {
      "type": "string",
      "title": "City"
    }
  },
  "form": [
    {
      "key": "city",
      "datalist": "cityname",
      "append": "<datalist id='cityname'><option value='Bochum'><option value='Berlin'></datalist>"
    }
  ]
}
boeckers commented 1 year ago

@tchapi

tchapi commented 1 year ago

Hello @boeckers

If we're to add a datalist, I'd rather properly implement it with something like this, that would automatically create a datalist and name it / fill it accordingly:

{
  "schema": {
    "city": {
      "type": "string",
      "title": "City"
    }
  },
  "form": [
    {
      "key": "city",
      "datalist": [
         "Bochum", "Berlin"
      ],
    }
  ]
}

WDYT @sdetweil ?

sdetweil commented 1 year ago

I agree, this has always been about hiding the implementation details in the definition

but, isn't this like an enum in the schema w a declarative style in the form ( having just played with checkboxes)

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.