Retrieving both values from dropdown

I am using a standard ui_dropdown widget, populated from a function which sets msg.option but for my use case I need to get (from the output) both selected label AND value, not just value.

Is there any way to achieve this?

Can you not just create the msg.options array to have a array as value, this array would hold the label and the value
e.g.

[{"one":["one",1]},{"two":["two",2]}]

Then when label one is selected the output would be ["one", 1]

It's what I am doing, but the msg.options is not coming out from the dropdown. Only msg.payload and topic. ( I have checked the "pass-thru")

The dropdown only returns msg.payload
The below image shows the drop down return an array which holds the label and value.


Clearly returning what you asked for the label and value.

You could send it as an object to.

1 Like

I tried your flow, but the dropdown is only sending the "value" and not the "label".

[{"id":"c27b3fdd1169ac09","type":"change","z":"fd95058a.48e3e8","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"[{\"Elisa Essentials\":\"tidal:playlist:f21450d7-c515-4dac-b446-ad93c64b0d3d\"},{\"I miei brani di Shazam\":\"tidal:playlist:4b639e84-4aca-4b17-808e-91113efee180\"},{\"Jazz Got Soul\":\"tidal:playlist:941851f7-7d06-4ddd-883c-834360c4ce74\"},{\"Kitty Margolis\":\"tidal:playlist:f0383781-3159-4bb0-9124-ff80cefbddda\"}]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":1320,"wires":[["a1a60971c32310d7","b1afb4d2f310774d"]]},{"id":"493b0a8adb95b651","type":"inject","z":"fd95058a.48e3e8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":1440,"wires":[["c27b3fdd1169ac09"]]},{"id":"a1a60971c32310d7","type":"debug","z":"fd95058a.48e3e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":300,"y":1380,"wires":[]},{"id":"b1afb4d2f310774d","type":"ui_dropdown","z":"fd95058a.48e3e8","name":"","label":"","tooltip":"","place":"Select option","group":"4143016bc7f8443b","order":4,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"topic","topicType":"msg","className":"","x":440,"y":1320,"wires":[["cfabfeaea1a6a8bf"]]},{"id":"cfabfeaea1a6a8bf","type":"debug","z":"fd95058a.48e3e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":600,"y":1280,"wires":[]},{"id":"4143016bc7f8443b","type":"ui_group","name":"Prova test","tab":"5b337e3b.68826","order":5,"disp":true,"width":"6","collapse":false,"className":""},{"id":"5b337e3b.68826","type":"ui_tab","name":"Servizi","icon":"home","order":3,"disabled":false,"hidden":false}]

You need to set up the object value to be an array and add the label there to

[{"id":"493b0a8adb95b651","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":2460,"wires":[["c27b3fdd1169ac09"]]},{"id":"c27b3fdd1169ac09","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"[\t   {\t       \"Elisa Essentials\":[\"Elisa Essentials\",\"tidal:playlist:f21450d7-c515-4dac-b446-ad93c64b0d3d\"]\t   },\t   {\t       \"I miei brani di Shazam\":[\"I miei brani di Shazam\",\"tidal:playlist:4b639e84-4aca-4b17-808e-91113efee180\"]\t   },\t   {\t       \"Jazz Got Soul\":[\"Jazz Got Soul\",\"tidal:playlist:941851f7-7d06-4ddd-883c-834360c4ce74\"]\t   },\t   {\t       \"Kitty Margolis\":[\"Kitty Margolis\",\"tidal:playlist:f0383781-3159-4bb0-9124-ff80cefbddda\"]\t   }\t]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":2340,"wires":[["a1a60971c32310d7","b1afb4d2f310774d"]]},{"id":"a1a60971c32310d7","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":2400,"wires":[]},{"id":"b1afb4d2f310774d","type":"ui_dropdown","z":"bf9e1e33.030598","name":"","label":"","tooltip":"","place":"Select option","group":"4143016bc7f8443b","order":4,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"topic","topicType":"msg","className":"","x":530,"y":2340,"wires":[["cfabfeaea1a6a8bf"]]},{"id":"cfabfeaea1a6a8bf","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":690,"y":2300,"wires":[]},{"id":"4143016bc7f8443b","type":"ui_group","name":"Prova test","tab":"5b337e3b.68826","order":5,"disp":true,"width":"6","collapse":false,"className":""},{"id":"5b337e3b.68826","type":"ui_tab","name":"Servizi","icon":"home","order":3,"disabled":false,"hidden":false}]

Basically construct the msg.options slightly different.

1 Like

Ahhh! That's a major PITA as I have to re-write the generating code...
I think I could fix by sending the array also in msg.topic (that will be relayed at the output) so I will then make an array lookup and find the label.

@E1cid Maybe I could find a function to convert the incoming data flow:

[{"name":"Adore Jazz","uri":"m3u:Adore%20Jazz.m3u8"},{"name":"Excluded","uri":"m3u:Excluded.m3u8"},{"name":"Radio Italia","uri":"m3u:Radio%20Italia.m3u"},{"name":"RadioEstere","uri":"m3u:RadioEstere.m3u8"},{"name":"Radiotunes","uri":"m3u:Radiotunes.m3u8"},{"name":"Suoni della natura","uri":"m3u:Suoni%20della%20natura.m3u8"},{"name":"random","uri":"m3u:random.m3u8"},{"name":"* I consigli dello staff","uri":"tidal:playlist:0108cc4a-91b0-47f5-a6ba-7769ca88b842"}]

into the one you suggested for the dropdown...

msg.options = msg.payload.map(obj => {
    return {[obj.name]: obj}
})
return msg;

would return msg.options as

[
    {"Adore Jazz":
        {"name":"Adore Jazz","uri":"m3u:Adore%20Jazz.m3u8"}},
    {"Excluded":
        {"name":"Excluded","uri":"m3u:Excluded.m3u8"}},
    {"Radio Italia":
        {"name":"Radio Italia","uri":"m3u:Radio%20Italia.m3u"}},
    {"RadioEstere": 
        {"name":"RadioEstere","uri":"m3u:RadioEstere.m3u8"}},
    {"Radiotunes":
       {"name":"Radiotunes","uri":"m3u:Radiotunes.m3u8"}},
    {"Suoni della natura":
       {"name":"Suoni della natura","uri":"m3u:Suoni%20della%20natura.m3u8"}},
    {"random":
       {"name":"random","uri":"m3u:random.m3u8"}},
    {"* I consigli dello staff":
       {"name":"* I consigli dello staff","uri":"tidal:playlist:0108cc4a-91b0-47f5-a6ba-7769ca88b842"}}]
1 Like

Thank you!

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