DROPDOWN keeps the selected value in memory

Hello,

I am using node red V1.2.9
and I want to do a multiple choice filter with some DROPDOWNs that I am attaching.
these filters go into a MYSQL database to extract a graph.
it works but one detail I have to systematically change all my dropdowns if I want to obtain a new result.
in CV dropdowns do not keep their choice selected during a future filter, their value is empty.
thank you for the help you can give me.

Hi Jerome, welcome to the forum.
You will be much more likely to get support if you post your question in English.
Most non-English speaking forum users, use Google Translate.
Hope this helps.

hi paul,
thank i have translate in english, you're right.

1 Like

You may refer to the following code. The code is a simplified version of the wireless vibration sensor sampling rate adjustment drop down menu.
You may modify and put the code inside a function node, then inject it to the dropdown menu node. When user changes an option, then the corresponding dropdown menu changes too, and a default selection is used. You keep your last selection, you can further use a context or flow. For example, flow.set('lastvalue', lastvalue), flow.get('lastvalue') and use this value as the payload to the dropdown menu.

switch(msg.payload)
{
    case 0:
        msg.options=[{'50Hz':50},{'100Hz':100},{'200Hz':200}];
        msg.payload=50;
        break;
    case 1:
        msg.options=[{'400Hz':400},{'800Hz':800},
            {'1.6kHz':1600},{'3.2kHz':3200},
            {'6.4kHz':6400},{'12.8kHz':12800},
            {'25.6kHz':25600}];
        msg.payload=1600;
        break;
    default:
        msg.options=[{'50Hz':50},{'100Hz':100},{'200Hz':200}];
        msg.payload=50;

}
return msg;
1 Like

thank david
I'm new to node red and flow.set / get I'm not sure how to use it. Could you give me an example on this flow please?

[{"id":"50e3259.e384cdc","type":"join","z":"49333661.928418","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1190,"y":1300,"wires":[[]]},{"id":"87aed3fa.bad11","type":"mui_dropdown","z":"49333661.928418","name":"","label":"select_1","tooltip":"","place":"Select option","group":"","order":1,"width":0,"height":0,"passthru":false,"options":[{"label":"choix_1","value":"1","type":"str"},{"label":"choix_2","value":"2","type":"str"},{"label":"choix_3","value":"3","type":"str"}],"payload":"","topic":"select_1","x":890,"y":1180,"wires":[["50e3259.e384cdc"]]},{"id":"8ed1b819.535fd8","type":"mui_dropdown","z":"49333661.928418","name":"","label":"select_2","tooltip":"","place":"Select option","group":"","order":1,"width":0,"height":0,"passthru":true,"options":[{"label":"test_1","value":"1","type":"str"},{"label":"test_2","value":"2","type":"str"},{"label":"test_3","value":"3","type":"str"},{"label":"test_4","value":"4","type":"str"}],"payload":"","topic":"select_2","x":920,"y":1480,"wires":[["50e3259.e384cdc"]]},{"id":"7ee4a0ef.b8ba8","type":"function","z":"49333661.928418","name":"complete","func":"\nreturn {\n    complete : true\n};","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1068,"y":1677.4832763671875,"wires":[["50e3259.e384cdc"]]},{"id":"71041f02.f1fbc","type":"mui_button","z":"49333661.928418","name":"","group":"","order":1,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"button","x":710,"y":1680,"wires":[["7ee4a0ef.b8ba8"]]}]

What is the "mui_dropdown" node that you are using? It is an unknown type. See attached picture:

Here is an example using the default dropdown node from the dashboard. The input to functions provides the dropdown list and selected value. Hopefully it is helpful.

[{"id":"26b7cfd06d09cc4c","type":"inject","z":"b00ebb4f.f20fd8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":790,"y":120,"wires":[["e7054019.301b8"]]},{"id":"4143a3f3f7aa4fe1","type":"inject","z":"b00ebb4f.f20fd8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":790,"y":160,"wires":[["e7054019.301b8"]]},{"id":"e7054019.301b8","type":"function","z":"b00ebb4f.f20fd8","name":"Adjust rate options","func":"var rate;\nswitch(msg.payload)\n{\n    \n    case 0:\n    case 1:\n        msg.options=[{'50Hz':50},{'100Hz':100},{'200Hz':200}];\n        msg.payload=50;\n        global.set('g_rate',50);\n        break;\n    case 2:\n    case 3:\n    case 4:\n    case 5:\n        msg.options=[{'400Hz':400},{'800Hz':800},\n            {'1.6kHz':1600},{'3.2kHz':3200},\n            {'6.4kHz':6400},{'12.8kHz':12800},\n            {'25.6kHz':25600}];\n        msg.payload=1600;\n        global.set('g_rate',1600);\n        break;\n    default:\n        msg.options=[{'50Hz':50},{'100Hz':100},{'200Hz':200}];\n        msg.payload=50;\n        global.set('g_rate',50);\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1090,"y":120,"wires":[["2d2f8d2324623926"]]},{"id":"2d2f8d2324623926","type":"ui_dropdown","z":"b00ebb4f.f20fd8","name":"","label":"Rate (Hz): ","tooltip":"","place":"Select option","group":"22fb5d88f54881ad","order":8,"width":6,"height":1,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"g_rate","topicType":"str","className":"","x":1120,"y":180,"wires":[["a436e820.534ba8"]]},{"id":"22fb5d88f54881ad","type":"ui_group","name":"DAQ Control","tab":"387c2951.8c0036","order":4,"disp":true,"width":"6","collapse":false},{"id":"387c2951.8c0036","type":"ui_tab","name":"Zone DAQ","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

For additional work, you need to use context to save your selection and feed into the function node.

Is that dropdown node from mdashboard? If so then you will be pretty much on your own. Few if any here use it. We use the standard dashboard node-red-dashboard. You must (I think) uninstall mdashboard if you want to use the standard one.

I use mdashboard because I want to do multi-user.
in fact I created a connected hive and I recover the data in the sql database.
and multi-user to have several beekeepers.
thank you for your help i will try.

1 Like

in my case I have 2 different input data dropdown 1 "apiary ID" and dropdown 2 "hive ID"
my filter works but if I want to redo a 2nd filtering without touching ID_RUCHER it does not work.
I have to refresh the page to redo a filter.

[{"id":"5856ccd0.d198f4","type":"join","z":"3ccc0f61.ff66e","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1710,"y":1560,"wires":[[]]},{"id":"b95d3a92.b52858","type":"function","z":"3ccc0f61.ff66e","name":"complete","func":"\nreturn {\n    complete : true\n};","outputs":1,"noerr":0,"x":1608,"y":1737.4832763671875,"wires":[["5856ccd0.d198f4"]]},{"id":"e5e6f39d.73fde","type":"ui_dropdown","z":"3ccc0f61.ff66e","name":"","label":"ID_rucher","tooltip":"","place":"Select option 1","group":"86228.687a5dd88","order":2,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"RUCHER_1","value":1,"type":"num"},{"label":"RUCHER_2","value":2,"type":"num"}],"payload":"","topic":"ID_RUCHIER","topicType":"msg","x":1500,"y":1540,"wires":[["5856ccd0.d198f4"]]},{"id":"7dab4c15.37aa04","type":"ui_dropdown","z":"3ccc0f61.ff66e","name":"","label":"ID_RUCHE","tooltip":"","place":"Select option 2","group":"86228.687a5dd88","order":2,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"ID_RUCHE","value":1,"type":"num"},{"label":"ID_RUCHE","value":2,"type":"num"},{"label":"ID_RUCHE","value":3,"type":"num"}],"payload":"","topic":"ID_RUCHE","topicType":"msg","x":1520,"y":1600,"wires":[["5856ccd0.d198f4"]]},{"id":"d13cf754.cbdb58","type":"ui_button","z":"3ccc0f61.ff66e","name":"","group":"86228.687a5dd88","order":4,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":1430,"y":1740,"wires":[["b95d3a92.b52858"]]},{"id":"86228.687a5dd88","type":"ui_group","name":"Default","tab":"e006699.f40dd98","order":1,"disp":true,"width":"6","collapse":false},{"id":"e006699.f40dd98","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

I understand the function with the switch keeps a default value but what I would like to do is keep a filter in memory or have a main filter with a secondary filter.

What do you mean by filter?
Your flow may have synchronization issue (If you select the dropdown options more than twice, then the join node can fire even if you do not push the button). A better way is to use "context", like I mentioned before.

You may try the following flow. It can give you some ideas/hints.

[{"id":"b95d3a92.b52858","type":"function","z":"79b070b85b1370e1","name":"complete","func":"var rucher=flow.get('rucher');\nvar ruche=flow.get('ruche');\n\n\nif(rucher!=null && ruche!=null)\n{\n    \n    var temp={};\n    temp.rucher=rucher;\n    temp.ruche=ruche;\n    temp.complete=true;\n    msg.payload=temp;\n    return msg;\n}\nelse\n    return null;    \n\n    \n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":520,"wires":[["fd9eb5e9f4543fe5"]]},{"id":"e5e6f39d.73fde","type":"ui_dropdown","z":"79b070b85b1370e1","name":"","label":"ID_rucher","tooltip":"","place":"Select option 1","group":"86228.687a5dd88","order":2,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"RUCHER_1","value":1,"type":"num"},{"label":"RUCHER_2","value":2,"type":"num"}],"payload":"","topic":"ID_RUCHIER","topicType":"msg","x":620,"y":380,"wires":[["21b7fd80207bff0e"]]},{"id":"7dab4c15.37aa04","type":"ui_dropdown","z":"79b070b85b1370e1","name":"","label":"ID_RUCHE","tooltip":"","place":"Select option 2","group":"86228.687a5dd88","order":2,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"ID_RUCHE","value":1,"type":"num"},{"label":"ID_RUCHE","value":2,"type":"num"},{"label":"ID_RUCHE","value":3,"type":"num"}],"payload":"","topic":"ID_RUCHE","topicType":"msg","x":640,"y":440,"wires":[["e8e5e6a824908dca"]]},{"id":"d13cf754.cbdb58","type":"ui_button","z":"79b070b85b1370e1","name":"","group":"86228.687a5dd88","order":4,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"ok","payloadType":"str","topic":"msg.topic","topicType":"str","x":630,"y":520,"wires":[["b95d3a92.b52858"]]},{"id":"21b7fd80207bff0e","type":"change","z":"79b070b85b1370e1","name":"","rules":[{"t":"set","p":"rucher","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":380,"wires":[[]]},{"id":"e8e5e6a824908dca","type":"change","z":"79b070b85b1370e1","name":"","rules":[{"t":"set","p":"ruche","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":440,"wires":[[]]},{"id":"fd9eb5e9f4543fe5","type":"debug","z":"79b070b85b1370e1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":980,"y":520,"wires":[]},{"id":"86228.687a5dd88","type":"ui_group","name":"Default","tab":"e006699.f40dd98","order":1,"disp":true,"width":"6","collapse":false},{"id":"e006699.f40dd98","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]


image
the first select with dropdown is good the second select a have ID_RUCHER an undefined!
beacause i think that i don't touch a dropdown ID_RUCHER but only dropdown ID_ruche.

I speak of filter because the dropdown allows me to filter in a database an apiary is a group of hives when I select a hive I cannot then pass to another hive.
the value of apiary will be empty because name change and not keep in memory

My flow just gives you an idea on how to implement this. You need to figure out why it is undefined by using the debug node.

I succeeded using the context variables, I share

[{"id":"aa63189a.fe0698","type":"function","z":"3ccc0f61.ff66e","name":"prepareQuery","func":"\n    var ID_RUCHIER = msg.payload.ID_RUCHIER;\n    \n\nif (typeof msg.payload.ID_RUCHIER == 'undefined')\n{\n   // node.warn(RUCHIER_1);\n    \n     ID_RUCHIER =context.get('RUCHIER_1');\n\n}else\n//if (ID_RUCHIER !== 'undefined')\n{\n    //\n      context.set('RUCHIER_1',msg.payload.ID_RUCHIER);\n}\n\n//var ID_RUCHIER = msg.payload.ID_RUCHIER;\nvar ID_RUCHE = msg.payload.ID_RUCHE;\n\n\nvar query;\nquery = \"SELECT * FROM `BASE_RUCHE` WHERE `ID_RUCHIER` LIKE '\"+ID_RUCHIER+\"' AND `ID_RUCHE` LIKE '\"+ID_RUCHE+\"' ORDER BY DATE;\";\n\n\nmsg.topic = query;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":860,"y":860,"wires":[["63d05e0c.9839a","78240206.58c04c"]]},{"id":"bc504912.83dd78","type":"join","z":"3ccc0f61.ff66e","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":690,"y":860,"wires":[["aa63189a.fe0698","b7e16a13.3fb048","c69b0310.2f3eb"]]},{"id":"142e014e.a0701f","type":"mui_dropdown","z":"3ccc0f61.ff66e","name":"","label":"ID_RUCHIER","tooltip":"","place":"Select option","group":"b29b3321.fcbe6","order":1,"width":0,"height":0,"passthru":false,"options":[{"label":"RUCHER_1","value":"1","type":"str"},{"label":"RUCHER_2","value":"2","type":"str"},{"label":"RUCHER_3","value":"3","type":"str"},{"label":"RUCHER_4","value":"4","type":"str"},{"label":"RUCHER_5","value":"5","type":"str"}],"payload":"","topic":"ID_RUCHIER","x":180,"y":840,"wires":[["bc504912.83dd78"]]},{"id":"4b19d6a3.dbef58","type":"mui_dropdown","z":"3ccc0f61.ff66e","name":"","label":"ID_RUCHE","tooltip":"","place":"Select option","group":"b29b3321.fcbe6","order":1,"width":0,"height":0,"passthru":true,"options":[{"label":"RUCHE_1","value":"1","type":"str"},{"label":"RUCHE_2","value":"2","type":"str"},{"label":"RUCHE_3","value":"3","type":"str"},{"label":"RUCHE_4","value":"4","type":"str"},{"label":"RUCHE_5","value":"5","type":"str"},{"label":"RUCHE_6","value":"6","type":"str"},{"label":"RUCHE_7","value":"7","type":"str"},{"label":"RUCHE_8","value":"8","type":"str"},{"label":"RUCHE_9","value":"9","type":"str"}],"payload":"","topic":"ID_RUCHE","x":170,"y":940,"wires":[["bc504912.83dd78"]]},{"id":"8c9b5ff3.44ab8","type":"function","z":"3ccc0f61.ff66e","name":"complete","func":"\nreturn {\n    complete : true\n};","outputs":1,"noerr":0,"x":568,"y":1237.4832763671875,"wires":[["bc504912.83dd78"]]},{"id":"37229945.834106","type":"mui_button","z":"3ccc0f61.ff66e","name":"","group":"b29b3321.fcbe6","order":1,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"button","x":210,"y":1240,"wires":[["8c9b5ff3.44ab8"]]},{"id":"b29b3321.fcbe6","type":"mui_group","name":"Choix Rucher & Ruche","tab":"db7ea857.fdac68","order":1,"disp":true,"width":"6","collapse":false},{"id":"db7ea857.fdac68","type":"mui_tab","name":"MES RUCHES","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

correct and improve

[{"id":"aa63189a.fe0698","type":"function","z":"3ccc0f61.ff66e","name":"prepareQuery","func":"\n    var ID_RUCHIER = msg.payload.ID_RUCHIER;\n    var ID_RUCHE = msg.payload.ID_RUCHE;\n    \n\nif (typeof msg.payload.ID_RUCHIER == 'undefined')\n{\n    \n     ID_RUCHIER =context.get('RUCHIER_1');\n\n}else\n{\n    \n      context.set('RUCHIER_1',msg.payload.ID_RUCHIER);\n}\n\n\nif (typeof msg.payload.ID_RUCHE == 'undefined')\n{\n \n    \n     ID_RUCHE =context.get('RUCHE_1');\n\n}else\n{\n    //\n      context.set('RUCHE_1',msg.payload.ID_RUCHE);\n}\n\n\nvar query;\nquery = \"SELECT * FROM `BASE_RUCHE` WHERE `ID_RUCHIER` LIKE '\"+ID_RUCHIER+\"' AND `ID_RUCHE` LIKE '\"+ID_RUCHE+\"' ORDER BY DATE;\";\n\n\nmsg.topic = query;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":860,"y":860,"wires":[["63d05e0c.9839a","78240206.58c04c"]]},{"id":"bc504912.83dd78","type":"join","z":"3ccc0f61.ff66e","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":690,"y":860,"wires":[["aa63189a.fe0698","b7e16a13.3fb048","c69b0310.2f3eb"]]},{"id":"4b19d6a3.dbef58","type":"mui_dropdown","z":"3ccc0f61.ff66e","name":"","label":"ID_RUCHE","tooltip":"","place":"Select option","group":"b29b3321.fcbe6","order":1,"width":0,"height":0,"passthru":true,"options":[{"label":"RUCHE_1","value":"1","type":"str"},{"label":"RUCHE_2","value":"2","type":"str"},{"label":"RUCHE_3","value":"3","type":"str"},{"label":"RUCHE_4","value":"4","type":"str"},{"label":"RUCHE_5","value":"5","type":"str"},{"label":"RUCHE_6","value":"6","type":"str"},{"label":"RUCHE_7","value":"7","type":"str"},{"label":"RUCHE_8","value":"8","type":"str"},{"label":"RUCHE_9","value":"9","type":"str"}],"payload":"","topic":"ID_RUCHE","x":170,"y":940,"wires":[["bc504912.83dd78"]]},{"id":"8c9b5ff3.44ab8","type":"function","z":"3ccc0f61.ff66e","name":"complete","func":"\nreturn {\n    complete : true\n};","outputs":1,"noerr":0,"x":568,"y":1237.4832763671875,"wires":[["bc504912.83dd78"]]},{"id":"37229945.834106","type":"mui_button","z":"3ccc0f61.ff66e","name":"","group":"b29b3321.fcbe6","order":1,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"button","x":210,"y":1240,"wires":[["8c9b5ff3.44ab8"]]},{"id":"142e014e.a0701f","type":"mui_dropdown","z":"3ccc0f61.ff66e","name":"","label":"ID_RUCHIER","tooltip":"","place":"Select option","group":"b29b3321.fcbe6","order":1,"width":0,"height":0,"passthru":false,"options":[{"label":"RUCHER_1","value":"1","type":"str"},{"label":"RUCHER_2","value":"2","type":"str"},{"label":"RUCHER_3","value":"3","type":"str"},{"label":"RUCHER_4","value":"4","type":"str"},{"label":"RUCHER_5","value":"5","type":"str"}],"payload":"","topic":"ID_RUCHIER","x":180,"y":840,"wires":[["bc504912.83dd78"]]},{"id":"b29b3321.fcbe6","type":"mui_group","name":"Choix Rucher & Ruche","tab":"db7ea857.fdac68","order":1,"disp":true,"width":"6","collapse":false},{"id":"db7ea857.fdac68","type":"mui_tab","name":"MES RUCHES","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
1 Like

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