Trigger ui nodes to output their value

Hello everyone!

I have a question: I have two numeric inputs filled with values (for testing purposes from inject nodes). If the user hits the "save" button, the values should be returned. Looks like this:
image

The flow is:

[{"id":"3569b227.fc29ce","type":"ui_numeric","z":"ec99b4da.293d4","name":"min","label":"min","tooltip":"","group":"89d6839e.8d47d8","order":2,"width":3,"height":1,"wrap":false,"passthru":false,"topic":"min","topicType":"str","format":"{{value}}","min":0,"max":"100","step":"5","x":350,"y":1040,"wires":[["42da1c55.d71764"]]},{"id":"dd5ddc3e.500d8","type":"ui_numeric","z":"ec99b4da.293d4","name":"max","label":"max","tooltip":"","group":"89d6839e.8d47d8","order":3,"width":3,"height":1,"wrap":true,"passthru":false,"topic":"max","topicType":"str","format":"{{value}}","min":0,"max":"100","step":"5","x":350,"y":1120,"wires":[["42da1c55.d71764"]]},{"id":"83f310d8.0a22b","type":"inject","z":"ec99b4da.293d4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"30","payloadType":"num","x":170,"y":1120,"wires":[["dd5ddc3e.500d8"]]},{"id":"f334195b.42c168","type":"inject","z":"ec99b4da.293d4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":170,"y":1040,"wires":[["3569b227.fc29ce"]]},{"id":"42da1c55.d71764","type":"join","z":"ec99b4da.293d4","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":570,"y":1080,"wires":[["4fca7c68.a8c934"]]},{"id":"4fca7c68.a8c934","type":"debug","z":"ec99b4da.293d4","name":"Input","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":1080,"wires":[]},{"id":"c7ed725b.53073","type":"ui_button","z":"ec99b4da.293d4","name":"","group":"89d6839e.8d47d8","order":4,"width":0,"height":0,"passthru":false,"label":"save interval","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":170,"y":1200,"wires":[["9be596c6.f41de8"]]},{"id":"9be596c6.f41de8","type":"change","z":"ec99b4da.293d4","name":"","rules":[{"t":"set","p":"complete","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":1200,"wires":[["42da1c55.d71764"]]},{"id":"89d6839e.8d47d8","type":"ui_group","name":"Interval Input","tab":"69262da4.f388b4","order":1,"disp":true,"width":"6","collapse":false},{"id":"69262da4.f388b4","type":"ui_tab","name":"Interval","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

The problem I'm facing is as follows: the numeric input fields pass their values to the join node only if the user changes the values. Sometimes only one of the two values is changed, thus only one value is returned in the debug output. Is there a way to (kind of) trigger the input nodes to pass their values along when pushing the "save" button?

Thanks in advance!

Side note: I could use the ui_form node, but I don't want to. With the numeric input nodes I have control over the allowed ranges...

You could store max and min in context when any value is change the context is updated, when you push th save the values are then read by context.
eg.

[{"id":"f334195b.42c168","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":70,"y":1820,"wires":[["3569b227.fc29ce"]]},{"id":"3569b227.fc29ce","type":"ui_numeric","z":"c74669a0.6a34f8","name":"min","label":"min","tooltip":"","group":"89d6839e.8d47d8","order":2,"width":3,"height":1,"wrap":false,"passthru":true,"topic":"min","topicType":"str","format":"{{value}}","min":0,"max":"100","step":"5","x":250,"y":1820,"wires":[["ed450630.c8a118"]]},{"id":"ed450630.c8a118","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"minmax","pt":"flow","to":"$merge([$flowContext(\"minmax\"),{$.topic:$.payload}])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":1860,"wires":[[]]},{"id":"dd5ddc3e.500d8","type":"ui_numeric","z":"c74669a0.6a34f8","name":"max","label":"max","tooltip":"","group":"89d6839e.8d47d8","order":3,"width":3,"height":1,"wrap":false,"passthru":true,"topic":"max","topicType":"str","format":"{{value}}","min":0,"max":"100","step":"5","x":250,"y":1900,"wires":[["ed450630.c8a118"]]},{"id":"83f310d8.0a22b","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"30","payloadType":"num","x":70,"y":1900,"wires":[["dd5ddc3e.500d8"]]},{"id":"c7ed725b.53073","type":"ui_button","z":"c74669a0.6a34f8","name":"","group":"89d6839e.8d47d8","order":4,"width":0,"height":0,"passthru":false,"label":"save interval","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":70,"y":1980,"wires":[["9be596c6.f41de8"]]},{"id":"9be596c6.f41de8","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"minmax","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":1980,"wires":[["4fca7c68.a8c934"]]},{"id":"4638f64b.7d9f6","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":100,"y":2040,"wires":[["9be596c6.f41de8"]]},{"id":"4fca7c68.a8c934","type":"debug","z":"c74669a0.6a34f8","name":"Input","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":450,"y":1980,"wires":[]},{"id":"89d6839e.8d47d8","type":"ui_group","name":"Interval Input","tab":"69262da4.f388b4","order":1,"disp":true,"width":"6","collapse":false},{"id":"69262da4.f388b4","type":"ui_tab","name":"Interval","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

That's a good idea! Thanks!

The only thing that's missing is to store the initial values as the input fields are filled. This way I will get the full output even if nothing was changed.

And I've seen once more: I really should try to learn JSONata :blush:

if you leave the injects and make them inject at deploy, you can inject the context values
e.g.

[{"id":"4ef67f3d.3eaab8","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":"0.1","topic":"","payload":"$flowContext(\"minmax.min\")","payloadType":"jsonata","x":160,"y":1800,"wires":[["33788f7a.9688d"]]},{"id":"33788f7a.9688d","type":"ui_numeric","z":"c74669a0.6a34f8","name":"min ","label":"min","tooltip":"","group":"89d6839e.8d47d8","order":2,"width":3,"height":1,"wrap":false,"passthru":false,"topic":"min","topicType":"str","format":"{{value}}","min":0,"max":"100","step":"5","x":330,"y":1800,"wires":[["c5764675.a0dc68"]]},{"id":"c5764675.a0dc68","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"minmax","pt":"flow","to":"$merge([$flowContext(\"minmax\"),{$.topic:$.payload}])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":1840,"wires":[[]]},{"id":"52650313.e4624c","type":"ui_numeric","z":"c74669a0.6a34f8","name":"max","label":"max","tooltip":"","group":"89d6839e.8d47d8","order":3,"width":3,"height":1,"wrap":false,"passthru":false,"topic":"max","topicType":"str","format":"{{value}}","min":0,"max":"100","step":"5","x":330,"y":1860,"wires":[["c5764675.a0dc68"]]},{"id":"c93fd5fd.b26e9","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":"0.1","topic":"","payload":"$flowContext(\"minmax.max\")","payloadType":"jsonata","x":180,"y":1880,"wires":[["52650313.e4624c"]]},{"id":"89d6839e.8d47d8","type":"ui_group","name":"Interval Input","tab":"69262da4.f388b4","order":1,"disp":true,"width":"6","collapse":false},{"id":"69262da4.f388b4","type":"ui_tab","name":"Interval","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

I used change nodes and JSONata but nothing is stopping you doing it in JS with a function node to.

Maybe a little bit explanation of the stuff around my little input form:

  • I have some source tabs where these intervals are used
  • I dont want to have this interval input form on every tab

My idea:

  • Have one tab with the interval input form
  • Have buttons on the other tabs
  • On button click: move to interval tab and fill in the actual values
  • On "save" click: send values back and move back to the original tab

Moving tabs is not the problem, I use ui_control. But now I have to somehow transfer my values. Either send the values directly (and receive them back) or store them in global context and use those (but have to extract them on the original tab)

My problems:

  1. How do I transfer my values from the source tabs to the interval tabs and set its flow context on entering the tab?
  2. The same applies to the name of the source tab to be able to jump back after save?
  3. How do I get the values back?

Do you have any ideas on that? (I really don't want to use e.g. MQTT to broadcast the values between flows, there must be some other way I don't see at the moment...)

Off the top of my head , there is ui control which can detect which tab has been opened, you could store previous tab. If values are stored as globals they should be accessible any where

Yes, but I'd like to avoid global variables (always reminds me of Fortran common blocks, something I never really became comfortable with...)

There must be a way. If I use a flow like this:

And push the button, I see the output:

Note the 3 debug messages:

  • "pre-jump" (on top): it has the params object set to my source tab I want to jump back
  • "ui control out" (on the bottom): params object is empty
  • "interval input" (in the middle): on my destination flow for the interval tab, the params object is empty as well

Purely from the existence of the param object in the ui_control output it seems to me that it should be possible to use it, thus avoiding globals

As long as all ui nodes are in same flow/tab then flow context should work fine.

Uicontrol, you would need to store the tab or name in an array adding new page to beginning and limiting length to 2, then array[1] would be previous page.

That's my last resort to put everything in the same flow...

It seems the params object is only used for url parameters: Msg.params from ui_control node That's a pity

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