# Select field - label for each value?

**URL:** <https://discourse.getcockpit.com/t/select-field-label-for-each-value/145>\
**Category:** General\
**Created:** [July 12, 2018, 9:08am UTC](https://discourse.getcockpit.com/t/select-field-label-for-each-value/145 "2018-07-12T09:08:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CristianE](https://avatars.discourse-cdn.com/v4/letter/c/ecc23a/32.png) [@CristianE](https://discourse.getcockpit.com/u/CristianE)\
**Post date:** [July 12, 2018, 9:08am UTC](https://discourse.getcockpit.com/t/select-field-label-for-each-value/145/1 "2018-07-12T09:08:20Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [September 27, 2018, 12:21pm UTC](https://discourse.getcockpit.com/t/select-field-label-for-each-value/145/2 "2018-09-27T12:21:00Z")

</div>

Now it is possible with the next branch for select and multipleselect fields.  
Commits: [here](https://github.com/agentejo/cockpit/commit/047ae6b6256e1eccf5104bec0c627244e84c028a) and [here](https://github.com/agentejo/cockpit/commit/c8007f3d62451d05c41bc151f6e9e5f9975e38a4)

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

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

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

```

or

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

```

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

---

<div class="post-metadata">

**Author:** ![Rozkalns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/rozkalns/32/114_2.png) [@Rozkalns](https://discourse.getcockpit.com/u/Rozkalns)\
**Post date:** [September 28, 2018, 1:04pm UTC](https://discourse.getcockpit.com/t/select-field-label-for-each-value/145/3 "2018-09-28T13:04:41Z")

</div>

Is it possible to set default value?

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [September 28, 2018, 2:31pm UTC](https://discourse.getcockpit.com/t/select-field-label-for-each-value/145/4 "2018-09-28T14:31:19Z")

</div>

Yes

select:

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

```

multipleselect:

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

```

---

<div class="post-metadata">

**Author:** ![Interpaul](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/interpaul/32/251_2.png) [@Interpaul](https://discourse.getcockpit.com/u/Interpaul)\
**Post date:** [February 22, 2019, 2:40pm UTC](https://discourse.getcockpit.com/t/select-field-label-for-each-value/145/5 "2019-02-22T14:40:16Z")

</div>

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”  
}

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [February 25, 2019, 8:21am UTC](https://discourse.getcockpit.com/t/select-field-label-for-each-value/145/6 "2019-02-25T08:21:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jasonday](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jasonday](https://discourse.getcockpit.com/u/jasonday)\
**Post date:** [March 27, 2019, 2:38pm UTC](https://discourse.getcockpit.com/t/select-field-label-for-each-value/145/7 "2019-03-27T14:38:35Z")

</div>

> [@CristianE](#):
>
> [  
> “option 1”,  
> “option 2”,  
> “option 3”,  
> ]

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"
          ]
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [March 27, 2019, 3:05pm UTC](https://discourse.getcockpit.com/t/select-field-label-for-each-value/145/8 "2019-03-27T15:05:48Z")

</div>

> [@jasonday](#):
>
> { “cls”:“”, “label”: “Standard”, “type”: “select”, “options”: [“1.1 Color”, “1.2 Contrast”] }

Please try

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

```

---

<div class="post-metadata">

**Author:** ![jasonday](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jasonday](https://discourse.getcockpit.com/u/jasonday)\
**Post date:** [March 27, 2019, 3:23pm UTC](https://discourse.getcockpit.com/t/select-field-label-for-each-value/145/9 "2019-03-27T15:23:09Z")

</div>

> [@artur](#):
>
> { “cls”:“”, “label”: “Standard”, “type”: “select”, “options”: { “options”: [“1.1 Color”, “1.2 Contrast”] } }

that did it - Thanks!
