Preload Date field in ui_form

Can anyone tell me how to preload a Date field in a ui_form? I have tried new Date(), new Date().getTime() and new Date().toISOString(). I can't think of anything else to try. I am able to preload other field types ok.

[{"id":"4e33788d.298f48","type":"debug","z":"bdd7be38.d3b55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":657,"y":733,"wires":[]},{"id":"f92257e5.9f821","type":"ui_form","z":"bdd7be38.d3b55","name":"Date form","label":"","group":"903a6ab8.4f4ca8","order":1,"width":0,"height":0,"options":[{"label":"Date","value":"date","type":"date","required":true,"rows":null}],"formValue":{"date":""},"payload":"","submit":"submit","cancel":"cancel","topic":"","x":481,"y":690,"wires":[["4e33788d.298f48"]]},{"id":"241b81f7.4e284e","type":"function","z":"bdd7be38.d3b55","name":"new Date()","func":"msg.payload = {date: new Date()}\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":641,"wires":[["f92257e5.9f821"]]},{"id":"caadbfef.f62a9","type":"inject","z":"bdd7be38.d3b55","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":92,"y":642,"wires":[["241b81f7.4e284e"]]},{"id":"75d480ef.1cc42","type":"function","z":"bdd7be38.d3b55","name":"new Date().getTime()","func":"msg.payload = {date: (new Date()).getTime()}\nreturn msg;","outputs":1,"noerr":0,"x":272,"y":693,"wires":[["f92257e5.9f821"]]},{"id":"b0047d05.6511c8","type":"inject","z":"bdd7be38.d3b55","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":93,"y":692,"wires":[["75d480ef.1cc42"]]},{"id":"a5dfc260.07496","type":"function","z":"bdd7be38.d3b55","name":"new Date().toISOString()","func":"msg.payload = {date: (new Date()).toISOString()}\nreturn msg;","outputs":1,"noerr":0,"x":283,"y":738,"wires":[["f92257e5.9f821"]]},{"id":"3fbcf94.86b2306","type":"inject","z":"bdd7be38.d3b55","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":94,"y":737,"wires":[["a5dfc260.07496"]]},{"id":"903a6ab8.4f4ca8","type":"ui_group","z":"","name":"Home","tab":"e2e6f4f5.56f91","disp":false,"width":"6","collapse":false},{"id":"e2e6f4f5.56f91","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

[Edit]

7 Apr 17:17:35 - [info] Node-RED version: v1.0.4
7 Apr 17:17:35 - [info] Node.js  version: v12.16.1
7 Apr 17:17:35 - [info] Linux 5.3.0-46-generic x64 LE
7 Apr 17:17:35 - [info] Loading palette nodes
7 Apr 17:17:36 - [info] Dashboard version 2.19.3 started at /ui

Hello,
What format does the node put out if you enter a date from the dashboard?
Sending messages in the same format as the output has worked for me using the form node in other input formats.
Johannes

Edit doesn’t work :slightly_frowning_face:

It appears to be iso string,

{"date":"2020-04-06T23:00:00.000Z"}

I have tried feeding exactly the above in an inject set to JSON and that doesn't work either.

yeah - ok - that's a bug... fix pushed to master branch if you want to try it.

1 Like

I installed using
npm install node-red/node-red-dashboard
and got 2.20.1-beta, restarted node red which confirmed the new version installed, but the test flow I posted still doesn't appear to do anything.
Edit, I think I should have replied to the previous post so that @dceejay would get notified, I keep forgetting to do that.

can you try this simple flow to test ?

[{"id":"5389c329.4deebc","type":"debug","z":"ea593186.4918d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":850,"y":1140,"wires":[]},{"id":"37564c24.db23f4","type":"ui_form","z":"ea593186.4918d","name":"Date form","label":"","group":"b10fbc0c.f705c","order":1,"width":0,"height":0,"options":[{"label":"Date","value":"date","type":"date","required":true,"rows":null},{"label":"Text","value":"text","type":"text","required":false,"rows":null},{"label":"Switch","value":"switch","type":"switch","required":false,"rows":null}],"formValue":{"date":"","text":"","switch":false},"payload":"","submit":"submit","cancel":"cancel","topic":"","x":680,"y":1140,"wires":[["5389c329.4deebc"]]},{"id":"bb58a406.4c9b98","type":"function","z":"ea593186.4918d","name":"","func":"msg.payload = {\n    \"date\":\"2021-02-20\",\n    \"text\":msg.payload + \"\",\n    \"switch\":true\n    \n};\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":1140,"wires":[["37564c24.db23f4","a974a3c9.064f7"]]},{"id":"1c4542aa.186c5d","type":"inject","z":"ea593186.4918d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":321,"y":1139,"wires":[["bb58a406.4c9b98"]]},{"id":"b10fbc0c.f705c","type":"ui_group","z":"","name":"Home","tab":"76d6a090.f21d2","disp":false,"width":"6","collapse":false},{"id":"76d6a090.f21d2","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

ensuring you have flushed browser cache first etc etc

In Waterfox the text and switch fields are updating but not the date. Surprisingly, in Chrome, none of them updates.

are you sure you have flushed the local browser cache - I've found some browsers "stickier" than others for holding onto old code.

I am ashamed to say that the problem with Waterfox was indeed the cache and now it works fine, with all the formats from my original sample (new Date(), new Date().getTime() and new Date().toISOString()). What part of Ctrl-F5 doesn't the browser understand I wonder.
However I still have a problem with Chrome, which is likely a completely different problem. None of the fields update, and in the browser console, immediately after telling it to clear absolutely everything, I see this, which suggests some is still being loaded from the cache, but I am not entirely sure about the meaning of what I am seeing.

this seems fairly informative - https://betterstudio.com/blog/clear-browser-cache/

but in your screen shot I would tick the box saying disable cache then ctrl-shift-R a couple of times.

I had cleared the cache using the method in the link, and I did it again just to be sure, with all the options in the dialog selected (cookies, history, etc) to no avail. I hadn't noticed the disable checkbox in the developer console and selecting that finally did it. What a pain. All working now, sorry about the hassle. I wish I hadn't tried Chrome now, I only did it in case the issue was Waterfox specific and instead it just wasted everybody's time.

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