Dropdown with preset option

The dashboard dropdown is set up with msg.options. A user selection shows the menu item and a payload is sent also.
However, the dropdown field initially only displays a message like "select".

How is it possible to "preset" the dropdown menu with sending an options set, display a specific item of the options directly and also send a payload for it?

I am not sure I fully understand. If you mean that you want to fill the dropdown with a set of options, then set it to show a particular option, and then send a message as if the user had selected that option then you can use two inject nodes. Set the first to fire after 0.1 seconds and configure it to send msg.options containing the selection options, and configure a second inject node to fire at 0.2 seconds which selects the required option. If the dropdown is configured to pass through messages then the second message will also be sent on from the node.
Example:

[{"id":"833750b8970624cb","type":"ui_dropdown","z":"bdd7be38.d3b55","name":"","label":"","tooltip":"","place":"Select option","group":"903a6ab8.4f4ca8","order":5,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"topic","topicType":"msg","className":"","x":1110,"y":660,"wires":[["d48c162f34eca317"]]},{"id":"85600131b7280b2d","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"options","v":"[\"A\",\"B\"]","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","x":920,"y":620,"wires":[["833750b8970624cb"]]},{"id":"d48c162f34eca317","type":"debug","z":"bdd7be38.d3b55","name":"debug 2518","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1260,"y":660,"wires":[]},{"id":"bcd98f5e7c2cd90a","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"0.2","topic":"","payload":"B","payloadType":"str","x":930,"y":700,"wires":[["833750b8970624cb"]]},{"id":"903a6ab8.4f4ca8","type":"ui_group","name":"Home","tab":"e2e6f4f5.56f91","order":1,"disp":false,"width":"6","collapse":false,"className":""},{"id":"e2e6f4f5.56f91","type":"ui_tab","name":"Home","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

@Colin
Yeah, that's basically what I'm looking for .... but some notes.
First, from further investigation, I learned sending msg.options can contain string(s) or / and array(s).
Important for preselecting a particular 'options' or 'pulldown element' the msg.payload for that must be the 'value'. For options with {'label':'value'} (which is my case), msg.payload must therefore be the "msg.payload = 'value'"! And use 'label', which is good using options with only a label. In that case 'value' for msg.payload it's the 'label'. I have missed that! :upside_down_face:
I'm not sure if it's necessary to use two msg for the build and extra for select, I'll have to double check.
I will test it and report back later.

In fact it is always the value. If a label is not provided in the options then the label defaults to the value entry.

Having tried it I see you are correct. The options and initial selection can be made in one message.

2 Likes

:+1: Your test saves me time, thanks

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