Sending a message with a value to a ui-form node time field

Is this possible? Has anyone achieved it? I tried looking at the output from the time field (which is a date of 1/1/1970 plus the time) and then tried lots of ways of creating such a date for the time I wanted.

I also tried converting the time to ms from midnight and send that as a number

Is it supposed to be possible?

Have you tried sending a Date object? Also try the number of milliseconds into the day. If neither works then post a flow just with an inject and the form node, so we can be absolutely certain we are trying to do the same as you.

1 Like

Thanks for your attention. Yes I have posted a date object. I've tried an awful lot of things. I can't get any reaction out of the time field on the form at all. I guess I must be doing something silly.

I attach my flow, 4 different tests trying -:
Test 1 Sending the same string from the output (copied manually from a debug node)
Test 2 Sending a date object
Test 3 Sending some millis (Desperation!)
Test 4 Sending the current date object

hmmmm...As I was typing this, I thought something I hadn't tried. I created a second form and wired the output from the first form to the input of the second form and keyed the time in. The date and text fields both appeared on the second form but the time did not!! (I haven't included this test below)

Here is the flow

[{"id":"f6ee4f19da65bed0","type":"inject","z":"99578642f6dfcf6a","name":"Test1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Test1","payloadType":"date","x":380,"y":160,"wires":[["8f04445decbb12cc"]]},{"id":"d416baa7e0fef104","type":"inject","z":"99578642f6dfcf6a","name":"Test2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Test2","payloadType":"date","x":380,"y":240,"wires":[["8f04445decbb12cc"]]},{"id":"c9213ff2bf89833c","type":"inject","z":"99578642f6dfcf6a","name":"Test3","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Test3","payloadType":"date","x":380,"y":320,"wires":[["8f04445decbb12cc"]]},{"id":"759e3c490e233e9f","type":"debug","z":"99578642f6dfcf6a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":260,"wires":[]},{"id":"8f04445decbb12cc","type":"function","z":"99578642f6dfcf6a","name":"","func":"let newMsg = {};\nnewMsg.topic = msg.topic;\nnewMsg.payload = {};\nif (msg.topic == \"Test1\") {\n    newMsg.payload.testText = \"Trying Time with Date String same as output\"\n    newMsg.payload.testDate = \"2021-11-01T00:00:00.000Z\"\n    newMsg.payload.testTime = \"1970-01-01T08:30:00.000Z\"\n}\nif (msg.topic == \"Test2\") {\n    timeDateObject = new Date(\"1970-01-01T08:30:00.000Z\");\n    newMsg.payload.testText = \"Trying Time with Date Object\"\n    newMsg.payload.testDate = \"2021-11-01T00:00:00.000Z\"\n    newMsg.payload.testTime = timeDateObject\n}\nif (msg.topic == \"Test3\") {\n    newMsg.payload.testText = \"Trying Time 12 minutes of milliseconds\"\n    newMsg.payload.testDate = \"2021-11-01T00:00:00.000Z\"\n    newMsg.payload.testTime = 12 * 60 * 1000\n}\nif (msg.topic == \"Test4\") {\n    timeDateObject = new Date();\n    newMsg.payload.testText = \"Trying Time (and Date) with current date\"\n    newMsg.payload.testDate = timeDateObject\n    newMsg.payload.testTime = timeDateObject\n}\n\nreturn newMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":260,"wires":[["a96cbaf6e99a8e95"]]},{"id":"a96cbaf6e99a8e95","type":"ui_form","z":"99578642f6dfcf6a","name":"","label":"","group":"e283bda8fc976c1d","order":2,"width":0,"height":0,"options":[{"label":"TestText","value":"testText","type":"text","required":true,"rows":null},{"label":"TestDate","value":"testDate","type":"date","required":true,"rows":null},{"label":"TestTime","value":"testTime","type":"time","required":true,"rows":null}],"formValue":{"testText":"","testDate":"","testTime":""},"payload":"","submit":"submit","cancel":"cancel","topic":"topic","topicType":"msg","splitLayout":"","x":870,"y":260,"wires":[["759e3c490e233e9f"]]},{"id":"888193c1ca0827b1","type":"inject","z":"99578642f6dfcf6a","name":"Test4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Test4","payloadType":"date","x":370,"y":380,"wires":[["8f04445decbb12cc"]]},{"id":"e283bda8fc976c1d","type":"ui_group","name":"Time On Form Test","tab":"4971deb59d615ef2","order":1,"disp":true,"width":"8","collapse":false},{"id":"4971deb59d615ef2","type":"ui_tab","name":"Time on Form Test","icon":"dashboard","order":5,"disabled":false,"hidden":false}]

All four of those examples work for me. What versions of node-red and node-red-dashboard are you using? If you are not using the latest dashboard then upgrade it. If that doesn't help then what browser are you using, on what OS?

1 Like

omigod! What an idiot......old dashboard Sorry to have wasted your time

1 Like

No problem, glad to have been of help.

2 Likes

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