I cannot write the code for the drop-down list correctly so that it is taken into account in the code. I still don't understand javascript and node-red well. Please tell me where I am wrong and how to write this code
Hi,
Input = 24
is saying set Input to 24, you want to use Input === 24
which is comparing Input to 24. Same with Output and Ethernet.
Now I have another problem, now "Control selection" does not work for me
What is msg.payload.Input and Output, are they numbers or strings?
These are numbers
Are they? show us
What about Ethernet?
better still, Post your flow please.
I asked you to post your flow, that means export the flow json and post here.
Hiighlight the flow(press control and click on a node)
press control e
copy to clipboard
and post here using </> button
[
{
"id": "07a15c3dc9fb10db",
"type": "ui_text",
"z": "210a9292a496473b",
"group": "1b74ebe8b8ff2c32",
"order": 3,
"width": 0,
"height": 0,
"name": "",
"label": "Control:",
"format": "{{msg.payload.result}}",
"layout": "col-center",
"className": "",
"x": 800,
"y": 300,
"wires": []
},
{
"id": "df3d4436d5f3c62f",
"type": "ui_form",
"z": "210a9292a496473b",
"name": "",
"label": "Control selection",
"group": "1b74ebe8b8ff2c32",
"order": 2,
"width": 0,
"height": 0,
"options": [
{
"label": "Input",
"value": "Input",
"type": "number",
"required": true,
"rows": null
},
{
"label": "Output",
"value": "Output",
"type": "number",
"required": true,
"rows": null
}
],
"formValue": {
"Input": "",
"Output": ""
},
"payload": "",
"submit": "submit",
"cancel": "cancel",
"topic": "S",
"topicType": "str",
"splitLayout": "",
"className": "",
"x": 210,
"y": 220,
"wires": [
[
"776066c2a108d36c"
]
]
},
{
"id": "ec7047541fc37ce2",
"type": "function",
"z": "210a9292a496473b",
"name": "",
"func": "Input=msg.payload.Input;\nOutput=msg.payload.Output;\nEthernet=msg.payload.Ethernet;\n\n\nif ((Input===24) && (Output===24) && (Ethernet===1)) {\n \n msg.payload.result = 'TM241CE24R';\n \n} else if ((Input===24) && (Output===24) && (Ethernet===0)) {\n \n msg.payload.result = 'TM241CE24T';\n \n} else {\n msg.payload.result = 'not';\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 600,
"y": 220,
"wires": [
[
"07a15c3dc9fb10db",
"e4942a47eaf766a8"
]
]
},
{
"id": "e4942a47eaf766a8",
"type": "debug",
"z": "210a9292a496473b",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 810,
"y": 220,
"wires": []
},
{
"id": "439b9c34aae7d4f4",
"type": "ui_dropdown",
"z": "210a9292a496473b",
"name": "Ethernet",
"label": "Ethernet",
"tooltip": "",
"place": "Select option",
"group": "1b74ebe8b8ff2c32",
"order": 1,
"width": 0,
"height": 0,
"passthru": true,
"multiple": false,
"options": [
{
"label": "Yes",
"value": 1,
"type": "num"
},
{
"label": "No",
"value": 0,
"type": "num"
}
],
"payload": "",
"topic": "E",
"topicType": "str",
"className": "",
"x": 200,
"y": 280,
"wires": [
[
"776066c2a108d36c"
]
]
},
{
"id": "776066c2a108d36c",
"type": "join",
"z": "210a9292a496473b",
"name": "join",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": true,
"timeout": "",
"count": "",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 430,
"y": 220,
"wires": [
[
"ec7047541fc37ce2"
]
]
},
{
"id": "1b74ebe8b8ff2c32",
"type": "ui_group",
"name": "Default1",
"tab": "b064614c916bb99e",
"order": 1,
"disp": true,
"width": "6",
"collapse": false,
"className": ""
},
{
"id": "b064614c916bb99e",
"type": "ui_tab",
"name": "Home5",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]
You had not given the form and dropdown different topic names, and the join node had no count
[{"id":"776066c2a108d36c","type":"join","z":"bf9e1e33.030598","name":"join","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":310,"y":3080,"wires":[["ec7047541fc37ce2"]]},{"id":"df3d4436d5f3c62f","type":"ui_form","z":"bf9e1e33.030598","name":"","label":"Control selection","group":"1b74ebe8b8ff2c32","order":2,"width":0,"height":0,"options":[{"label":"Input","value":"Input","type":"number","required":true,"rows":null},{"label":"Output","value":"Output","type":"number","required":true,"rows":null}],"formValue":{"Input":"","Output":""},"payload":"","submit":"submit","cancel":"cancel","topic":"form","topicType":"str","splitLayout":"","className":"","x":90,"y":3080,"wires":[["776066c2a108d36c"]]},{"id":"439b9c34aae7d4f4","type":"ui_dropdown","z":"bf9e1e33.030598","name":"Ethernet","label":"Ethernet","tooltip":"","place":"Select option","group":"1b74ebe8b8ff2c32","order":1,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"Yes","value":1,"type":"num"},{"label":"No","value":0,"type":"num"}],"payload":"","topic":"ethernet","topicType":"str","className":"","x":80,"y":3140,"wires":[["776066c2a108d36c"]]},{"id":"ec7047541fc37ce2","type":"function","z":"bf9e1e33.030598","name":"","func":"Input=msg.payload.form.Input;\nOutput=msg.payload.form.Output;\nEthernet=msg.payload.ethernet;\n\n\nif ((Input===24) && (Output===24) && (Ethernet===1)) {\n \n msg.payload.result = 'TM241CE24R';\n \n} else if ((Input===24) && (Output===24) && (Ethernet===0)) {\n \n msg.payload.result = 'TM241CE24T';\n \n} else {\n msg.payload.result = 'not';\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":3080,"wires":[["07a15c3dc9fb10db","e4942a47eaf766a8"]]},{"id":"07a15c3dc9fb10db","type":"ui_text","z":"bf9e1e33.030598","group":"1b74ebe8b8ff2c32","order":3,"width":0,"height":0,"name":"","label":"Control:","format":"{{msg.payload.result}}","layout":"col-center","className":"","x":680,"y":3160,"wires":[]},{"id":"e4942a47eaf766a8","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":3220,"wires":[]},{"id":"1b74ebe8b8ff2c32","type":"ui_group","name":"Default1","tab":"b064614c916bb99e","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"b064614c916bb99e","type":"ui_tab","name":"Home5","icon":"dashboard","disabled":false,"hidden":false}]
try this
Thank you very much, everything works! You helped a lot)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.