Select field - label for each value?

A ‘select’ field allows me to specify values that also get displayed as labels:

{
“options”: [
“option 1”,
“option 2”,
“option 3”,
]
}

Can we use the select field the same way we do in html - with a Label that is visible in the CMS and a Value that is not visible in the cms, but gets passed as data?

If not, then what would be a good workaround for that with Cockpit?

Thank you!

Now it is possible with the next branch for select and multipleselect fields.
Commits: here and here

{"options": "a,b,c"} or {"options":["a","b","c"]} work like before and

now it is possible to use labels in this two ways:

{
  "options": {
    "a": "one",
    "b": "two"
  }
}

or

{
  "options": [
    {
      "value": "a",
      "label": "one"
    },
    {
      "value": "b",
      "label": "two"
    }
  ]
}

Yay! :smile: And I’m sure, this new feature will eliminate some workarounds with collection-links + small/static helper collections to have the same functionality.

1 Like

Is it possible to set default value?

Yes

select:

{
  "options": "a,b,c",
  "default": "a"
}

multipleselect:

{
  "options": {
    "a": "one",
    "b": "two"
  },
  "default": ["a"]
}
3 Likes

I always get an empty option in the select, even though I defined a default option. Am I missing something?

{
“options”: “a,b,c”,
“default”: “a”
}

It should work. Did you change the field type from text to select or multipleselect (stupid mistake, but I do it quite often)?
What’s your Cockpit version?

I have the same issue when trying to use a select within a repeater:

{
  "field": {
    "type": "set",
    "name": "user_stories",
    "label": "User story",
    "options": {
      "display": "user_title",
      "fields": [
        {
          "name": "user_title",
          "type": "text",
          "label": "Title"
        },
        {
          "name": "user_desc",
          "type": "wysiwyg",
          "label": "Description"
        },
        {
          "cls":"",
          "label": "Standard",
          "type": "select",
          "options": [
            "1.1 Color",
            "1.2 Contrast"
          ]
        }
      ]
    }
  }
}

Please try

{
    "cls":"",
    "label": "Standard",
    "type": "select",
    "options": {
        "options": [
            "1.1 Color",
            "1.2 Contrast"
        ]
    }
}
3 Likes

that did it - Thanks!