Default Value for Dropdown

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.

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

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

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

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.

Which version of dashboard are you using?

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

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

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.

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...

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.

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

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.

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

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).

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

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