Text node doesn't show empty spaces (if generated by a function)

Hi, that's strange, if I inject a string with spaces they are correctly displayed, if I use a function it doesn't show the space, please consider this flow:

[{"id":"d906ef38.9de2c","type":"ui_text","z":"cc2c1666.3d904","group":"cad2b1e9.412298","order":2,"width":0,"height":0,"name":"time","label":"","format":"{{msg.payload}}","layout":"row-center","x":1310,"y":1720,"wires":[]},{"id":"c1e98346.64745","type":"inject","z":"cc2c1666.3d904","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":true,"onceDelay":"2","topic":"","payload":"","payloadType":"date","x":790,"y":1720,"wires":[["fbc6f385.caca38"]]},{"id":"fbc6f385.caca38","type":"simpletime","z":"cc2c1666.3d904","name":"Clock","mydate":true,"myymd":false,"myyear":false,"mymonth":false,"mymonthn":false,"mydom":false,"mydoy":false,"myday":false,"myhourpm":false,"myhour":true,"mytime":false,"mytimes":false,"myminute":true,"myminutes":false,"mysecond":true,"mymillis":false,"myepoch":false,"myrawdate":false,"mypm":false,"x":970,"y":1720,"wires":[["c37b259d.90424"]]},{"id":"c37b259d.90424","type":"function","z":"cc2c1666.3d904","name":"","func":"if (msg.mysecond%2==1) {duepunti=\":\";} else {duepunti=\" \";}\nmsg1={payload:msg.mydate};\nmsg2={payload:msg.myhour+\" \"+duepunti+\" \"+msg.myminute};\nreturn [msg1,msg2];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1150,"y":1720,"wires":[["a5b8ae14.0e046"],["d906ef38.9de2c"]]},{"id":"a5b8ae14.0e046","type":"ui_text","z":"cc2c1666.3d904","group":"cad2b1e9.412298","order":1,"width":0,"height":0,"name":"date","label":"","format":"{{msg.payload}}","layout":"row-center","x":1310,"y":1680,"wires":[]},{"id":"cad2b1e9.412298","type":"ui_group","name":"6Colonna","tab":"ef482f31.2d1628","order":6,"disp":false,"width":"6","collapse":false},{"id":"ef482f31.2d1628","type":"ui_tab","name":"Franco","icon":"dashboard","disabled":false,"hidden":true}]

Please consider properly formatting all flows in a topic :slight_smile:
Use the </> icon in the topic editor screen

EDIT - Thanks zen, for the formatting edit on OP behalf

@GiovanniG with HTML (which is what get generated for the dashboard), the browser automatically reduces multiple spaces to one space (see: 4 Easy Ways to Insert Spaces in HTML) so you need to insert a non-breaking space character. Try this, change your function node to this

if (msg.mysecond%2==1) {duepunti=":";} else {duepunti="&nbsp;";}
msg1={payload:msg.mydate};
msg2={payload:msg.myhour+"&nbsp;"+duepunti+"&nbsp;"+msg.myminute};
return [msg1,msg2];

and see if that does it for you.

1 Like

thanks a lot!

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