# Default Value for Dropdown

**URL:** https://discourse.nodered.org/t/default-value-for-dropdown/34852
**Category:** Dashboard
**Created:** [26 October 2020 18:48 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852 "2020-10-26T18:48:30Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![smilerz](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@smilerz](https://discourse.nodered.org/u/smilerz)
#### Post date: [26 October 2020 18:48 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/1 "2020-10-26T18:48:30Z")

</div>

I followed examples found elsewhere in the forums and am unable to set a default value in the dropdowns for lists that contain display and value fields.

I believe that the following should work - the value of the drop down is set, but no default selection is applied.

```auto
[{"id":"ef15c9a9.949c38","type":"inject","z":"fe186dcf.5aeb9","name":"","props":[{"p":"payload"},{"p":"options","v":"[\t{\"Option 1\":\"One\"},\t{\"Option 2\":\"Two\"},\t{\"Option 3\":\"Three\"},\t{\"Option 4\":\"Four\"},\t{\"Option 5\":\"Five\"}\t]","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":1060,"y":260,"wires":[["f63cb407.a84d48"]]},{"id":"f63cb407.a84d48","type":"ui_dropdown","z":"fe186dcf.5aeb9","name":"","label":"Drop Down","tooltip":"","place":" ","group":"d64da6be.97dca8","order":1,"width":5,"height":1,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":1210,"y":260,"wires":[["60cff7ed.75ccd8"]]},{"id":"60cff7ed.75ccd8","type":"debug","z":"fe186dcf.5aeb9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1370,"y":260,"wires":[]},{"id":"d64da6be.97dca8","type":"ui_group","name":"Shopping","tab":"76d02495.1ef9cc","order":1,"disp":true,"width":6,"collapse":false},{"id":"76d02495.1ef9cc","type":"ui_tab","name":"Alexa Lists","icon":"list","order":5,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [26 October 2020 18:54 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/2 "2020-10-26T18:54:09Z")

</div>

You need to send it the actual value of the option you want... sending 2 won't do it... as 2 is not one of your values

```auto
[{"id":"ef15c9a9.949c38","type":"inject","z":"eeee575.b4b80a8","name":"","props":[{"p":"payload"},{"p":"options","v":"[\t{\"Option 1\":\"One\"},\t{\"Option 2\":\"Two\"},\t{\"Option 3\":\"Three\"},\t{\"Option 4\":\"Four\"},\t{\"Option 5\":\"Five\"}\t]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Two","payloadType":"str","x":250,"y":720,"wires":[["f63cb407.a84d48"]]},{"id":"f63cb407.a84d48","type":"ui_dropdown","z":"eeee575.b4b80a8","name":"","label":"Drop Down","tooltip":"","place":" ","group":"d64da6be.97dca8","order":1,"width":5,"height":1,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":400,"y":720,"wires":[["60cff7ed.75ccd8"]]},{"id":"60cff7ed.75ccd8","type":"debug","z":"eeee575.b4b80a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":560,"y":720,"wires":[]},{"id":"d64da6be.97dca8","type":"ui_group","name":"Shopping","tab":"76d02495.1ef9cc","order":1,"disp":true,"width":6,"collapse":false},{"id":"76d02495.1ef9cc","type":"ui_tab","name":"Alexa Lists","icon":"list","order":5,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

### Author: ![smilerz](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@smilerz](https://discourse.nodered.org/u/smilerz)
#### Post date: [26 October 2020 19:31 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/3 "2020-10-26T19:31:55Z")

</div>

I had tried that method as well with the same result.  
Just to ensure I wasn't doing something dumb I imported your flow - but that didn't set the default value either.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [26 October 2020 19:32 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/4 "2020-10-26T19:32:45Z")

</div>

Which version of dashboard are you using?

---

<div class="post-metadata">

### Author: ![smilerz](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@smilerz](https://discourse.nodered.org/u/smilerz)
#### Post date: [26 October 2020 19:34 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/5 "2020-10-26T19:34:13Z")

</div>

2.23.4 with nodered v1.2.2 - which I believe are current versions for both.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [26 October 2020 21:13 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/6 "2020-10-26T21:13:31Z")

</div>

For me the example shows the correct default in the status but not in the field itself.  
@dceejay did you see this other problem I have with the dropdown on 2.23.4? Likely not related though. [V2.23.4 Dropdown sending numbers instead of strings](https://discourse.nodered.org/t/v2-23-4-dropdown-sending-numbers-instead-of-strings/34815)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 October 2020 10:08 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/7 "2020-10-27T10:08:47Z")

</div>

This has been fixed in master, along with what I assume is a related issue that refreshing a page with dropdowns on could lose the displayed value. To install for testing go to your .node-red directory and run  
`npm install node-red/node-red-dashboard`  
Note that this may take tens of minutes on Pi 3 and presumably hours on a Zero.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [27 October 2020 11:05 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/8 "2020-10-27T11:05:54Z")

</div>

> [@Colin](#):
>
> this may take tens of minutes...

yes - I have no idea why this is happening with npm now... - I have tried the alternative yarn installer and it takes about 20 secs... still I will probably ship it to npm later today anyway...

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 October 2020 11:22 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/9 "2020-10-27T11:22:35Z")

</div>

> [@dceejay](#):
>
> I have no idea why this is happening with npm now

I assumed it was just because it was having to compile it, most of the time it is in the C compiler. It isn't slow installing the current version from the repository.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [27 October 2020 11:30 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/10 "2020-10-27T11:30:53Z")

</div>

there is no compile - just pulling the same packages as if it was on npm (but obviously not that simple.)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 October 2020 12:02 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/11 "2020-10-27T12:02:06Z")

</div>

Well it spent a many minutes running cc1plus so it must have been compiling something.  
I am trying again using the command line  
`npm install --loglevel verbose --production node-red/node-red-dashboard`  
After several minutes it is hogging the processor running cc1plus and in the log I see  
`rollbackFailedOptional: verb prepareGitDep undefined: installing devDeps and running prepare script`  
Which seems odd since I said --production.

---

<div class="post-metadata">

### Author: ![smilerz](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@smilerz](https://discourse.nodered.org/u/smilerz)
#### Post date: [27 October 2020 15:22 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/12 "2020-10-27T15:22:18Z")

</div>

> [@Colin](#):
>
> This has been fixed in master, along with what I assume is a related issue that refreshing a page with dropdowns on could lose the displayed value. To install for testing go to your .node-red directory and run  
> `npm install node-red/node-red-dashboard`  
> Note that this may take tens of minutes on Pi 3 and presumably hours on a Zero.

I ran the npm install - restarted nodered and the example flow above still does not behave as expected.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 October 2020 15:56 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/13 "2020-10-27T15:56:13Z")

</div>

Were you in your .node-red folder when you ran the install?  
Go to the editor and refresh the page, if you then click the Hamburger menu what version does it say that node red is (down at the bottom).

---

<div class="post-metadata">

### Author: ![smilerz](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@smilerz](https://discourse.nodered.org/u/smilerz)
#### Post date: [27 October 2020 16:27 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/14 "2020-10-27T16:27:16Z")

</div>

that was it - dumb mistake! thanks, everything is working as expected now.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [10 November 2020 16:27 UTC](https://discourse.nodered.org/t/default-value-for-dropdown/34852/15 "2020-11-10T16:27:17Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
