# Preselect option in dynamically filled Dropdown

**URL:** <https://discourse.nodered.org/t/preselect-option-in-dynamically-filled-dropdown/34124>\
**Category:** Dashboard\
**Created:** [12 October 2020 12:40 UTC](https://discourse.nodered.org/t/preselect-option-in-dynamically-filled-dropdown/34124 "2020-10-12T12:40:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gebuhl](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@gebuhl](https://discourse.nodered.org/u/gebuhl)\
**Post date:** [12 October 2020 12:40 UTC](https://discourse.nodered.org/t/preselect-option-in-dynamically-filled-dropdown/34124/1 "2020-10-12T12:40:45Z")

</div>

It is possible to select an option in a prefilled dropdown.  
But how can I select an option in an dynamically filled dropdown?

I still made tests with prefilled and dynamically filled dropdown, but only the prefilled dropdown will show the selected option. The dynamially filled dropdown is giving me the output, but the option is not shown on the UI.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 October 2020 12:50 UTC](https://discourse.nodered.org/t/preselect-option-in-dynamically-filled-dropdown/34124/2 "2020-10-12T12:50:07Z")

</div>

Yes by feeding in msg.payload with the value of the selection you want pre selected

e.g.

```auto
[{"id":"55f374bb.7d3eb4","type":"inject","z":"7760f563.ea0324","name":"","props":[{"p":"payload"},{"p":"options","v":"[\"one\",\"two\",\"three\"]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"two","payloadType":"str","x":170,"y":2120,"wires":[["318c812a.d34f46","a3703f7a.e5aee"]]},{"id":"a3703f7a.e5aee","type":"ui_dropdown","z":"7760f563.ea0324","name":"","label":"","tooltip":"","place":"Select option","group":"165e1e1a.e752fa","order":1,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":280,"y":2200,"wires":[[]]},{"id":"165e1e1a.e752fa","type":"ui_group","z":"","name":"Default","tab":"f9b58883.fa613","order":1,"disp":true,"width":"12","collapse":false},{"id":"f9b58883.fa613","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![gebuhl](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@gebuhl](https://discourse.nodered.org/u/gebuhl)\
**Post date:** [12 October 2020 13:31 UTC](https://discourse.nodered.org/t/preselect-option-in-dynamically-filled-dropdown/34124/3 "2020-10-12T13:31:49Z")

</div>

I already tested.  
I works with prefilled dropdowns, but not with dynamically filled ones:

```auto
[{"id":"912a20c6.5c749","type":"ui_dropdown","z":"416fb8ac.762a48","name":"test","label":"test","tooltip":"","place":"test","group":"deeee64c.743b28","order":3,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"test","x":750,"y":900,"wires":[["baf73052.58ae4"]]},{"id":"55f19a36.83c904","type":"inject","z":"416fb8ac.762a48","name":"Setup","props":[{"p":"options","v":"[\"Test 1\",\"Test 2\",\"Test 3\",\"Test 4\",\"Test 5\"]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":410,"y":880,"wires":[["878ef56.1168008"]]},{"id":"dab6e71b.37ab28","type":"inject","z":"416fb8ac.762a48","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"test_3","payloadType":"str","x":590,"y":920,"wires":[["912a20c6.5c749","6ce0ff1a.b846f"]]},{"id":"baf73052.58ae4","type":"debug","z":"416fb8ac.762a48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":920,"wires":[]},{"id":"878ef56.1168008","type":"function","z":"416fb8ac.762a48","name":"setup data","func":"var newMsg = {\n 'options': []\n};\n\nfor (i = 0; i < 10; i++) {\n const name = 'Test ' + i;\n const id = 'test_' + i;\n var entry = {};\n entry[name] = id;\n newMsg.options.push(entry);\n}\n\nreturn newMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":570,"y":880,"wires":[["912a20c6.5c749","dd13caa8.d20698"]]},{"id":"dd13caa8.d20698","type":"debug","z":"416fb8ac.762a48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":860,"wires":[]},{"id":"6ce0ff1a.b846f","type":"ui_dropdown","z":"416fb8ac.762a48","name":"","label":"test","tooltip":"","place":"Select option","group":"deeee64c.743b28","order":4,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"Test 0","value":"test_0","type":"str"},{"label":"Test 1","value":"test_1","type":"str"},{"label":"Test 2","value":"test_2","type":"str"},{"label":"Test 3","value":"test_3","type":"str"},{"label":"Test 4","value":"test_4","type":"str"},{"label":"Test 5","value":"test_5","type":"str"},{"label":"Test 6","value":"test_6","type":"str"},{"label":"Test 7","value":"test_7","type":"str"},{"label":"Test 8","value":"test_8","type":"str"},{"label":"Test 9","value":"test_9","type":"str"}],"payload":"","topic":"","x":750,"y":940,"wires":[["baf73052.58ae4"]]},{"id":"1b26ffc8.734e4","type":"inject","z":"416fb8ac.762a48","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"test_4","payloadType":"str","x":590,"y":960,"wires":[["912a20c6.5c749","6ce0ff1a.b846f"]]},{"id":"deeee64c.743b28","type":"ui_group","z":"","name":"Information","tab":"cee61e6a.a801e","order":2,"disp":true,"width":"6","collapse":false},{"id":"cee61e6a.a801e","type":"ui_tab","z":"","name":"Konfiguration","icon":"settings","order":1,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 October 2020 13:36 UTC](https://discourse.nodered.org/t/preselect-option-in-dynamically-filled-dropdown/34124/4 "2020-10-12T13:36:26Z")

</div>

my example was dynamic , not prefilled.

Edit/  
Your flow works for me and test 3 and test 4 are preselected when i look at dashboard.

---

<div class="post-metadata">

**Author:** ![gebuhl](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@gebuhl](https://discourse.nodered.org/u/gebuhl)\
**Post date:** [12 October 2020 13:57 UTC](https://discourse.nodered.org/t/preselect-option-in-dynamically-filled-dropdown/34124/5 "2020-10-12T13:57:55Z")

</div>

What is your system?

I'm on Windows 10,  
Node-Red: v1.1.3,  
Node.js: v12.19.0,  
node-red-dashboard: 2.23.4

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 October 2020 14:03 UTC](https://discourse.nodered.org/t/preselect-option-in-dynamically-filled-dropdown/34124/6 "2020-10-12T14:03:08Z")

</div>

Android 6,  
Node-Red: v1.1.2,  
Node.js: v13,  
node-red-dashboard: 2.23.4

 ![Screenshot_20201012-150456](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/43eb02851883a522797918d96fc9109170a1cb7e.png)

---

<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:** [11 November 2020 14:03 UTC](https://discourse.nodered.org/t/preselect-option-in-dynamically-filled-dropdown/34124/7 "2020-11-11T14:03:22Z")

</div>

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