agentejo / cockpit

Add content management functionality to any site - plug & play / headless / api-first CMS
http://getcockpit.com
MIT License
5.4k stars 525 forks source link

[request] additional field types #822

Open RoelantStegmann opened 6 years ago

RoelantStegmann commented 6 years ago

Is it possible to extend the field types with some additional ones?

Integer / Numeric Use case: we want to keep some prices in the database, but want to enforce it to be numeric. It are standard JSON datatypes so it feels like they would fit.

RepeaterSet Use case: we want to for example add multiple alt- title - image combinations, or firstname - lastname combinations to one object. Respectively images for a product or stores with two contact persons. For this you would want to use Repeater on a combination of several fields.

DigitalGoldfish commented 6 years ago

Regarding the RepeaterSet - this is something that you can already do by putting a set field inside a repeater. You will have to do the configuration in the options field ... there is no UI for this.

Here's an example:

"field": {
    "type": "set",
    "name": "links",
    "label": "Links",
    "options": {
        {
          "fields": [
            {
              "name": "name",
              "label": "Name",
              "type": "text",
              "localize": true
            },
            {
              "name": "url",
              "label": "Adresse",
              "type": "text",
              "localize": true
            },
            {
              "name": "type",
              "type": "select",
              "label": "Link-Typ",
              "options": {
                "options": "Webseite, Email",
                "default": "Webseite"
              }
            }
          ]
        }
    },
    "display": null
}

P.S.: I usually just edit the PHP schema files directly bypassing the UI.

piotr-cz commented 6 years ago

This is how I've build field to create multiple files with label based on @DigitalGoldfish answer

{
  "field": {
    "type": "set",
    "name": "items",
    "label": "Item",
    "options": {
      "fields": [
        {
          "name": "label",
          "label": "Label",
          "type": "text"
        },
        {
          "name": "file",
          "label": "File",
          "type": "file"
        }
      ]
    }
  }
}
ronbravo commented 5 years ago

@RoelantStegmann Not sure if this helps but, I've been updating the schema by API Rest call. I just added a type like so: { name: 'total', type: 'number', info: 'Random total for user' } Then when I inspect the entry in the SQLLite DB it seems to be saving the entry for total as a number.

For example:

{
   "alias":"toni taylor",
   "email":"toni.taylor@example.com",
   "image":"https:\/\/randomuser.me\/api\/portraits\/women\/55.jpg",
   "username":"goldenladybug322",
   "total":667,
   "_by":null,
   "_modified":1545413933,
   "_uid":"",
   "_creatorId":"",
   "_updated":"",
   "_status":"",
   "_metaInfoId":"",
   "accountId":"",
   "accountMeta":"",
   "password":"",
   "role":"",
   "type":"",
   "_created":1545413933,
   "_id":"5c1d252d303938005300006b"
}

I notice there was a ticket for adding integer, decimal types for the textarea and it was closed without saying why? Maybe Cockpit already supports this?

slowdub commented 5 years ago

Using Text field accepts all standard html input options, so you could build something like: Float:

{
  "type": "number",
  "placeholder": "float",
  "step": 0.1
}

Int:

{
  "type": "number",
  "placeholder": "integer",
  "pattern": "/^[1-9][0-9]*$/"
}

Now, type (type: number) property is not described in current docs, so it's hard to tell if this is part of API or internals that might change.

Happy to update docs if @aheinze 👍 of officially supporting type property.