Select field - label for each value?


#1

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!


#2

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.


#3

Is it possible to set default value?


#4

Yes

select:

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

multipleselect:

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