How to get text input value


#1

Hi all,

I have a flow where I have a text input. I do a select from a db and fill the data in that text input. Then I want to change that text and save it (means do another query and update it in db).
I managed to put in text input the text i read from db but I am not able to get it's value when i press save...
Any help on that?
Thanks

[{"id":"aa98e43.bcd4418","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"407e1f98.f54d8","type":"function","z":"aa98e43.bcd4418","name":"query ins logo","func":"msg.topic = \"SELECT * FROM ins_logo\"\n\nreturn msg;","outputs":1,"noerr":0,"x":374,"y":215,"wires":[["59d7c426.a7093c"]]},{"id":"59d7c426.a7093c","type":"mysql","z":"aa98e43.bcd4418","mydb":"c1295981.fb5958","name":"usvstdt","x":558,"y":215,"wires":[["dacea586.f41748"]]},{"id":"dacea586.f41748","type":"change","z":"aa98e43.bcd4418","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0].name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":760.5,"y":215,"wires":[["b51e306c.5902b"]]},{"id":"b51e306c.5902b","type":"ui_text_input","z":"aa98e43.bcd4418","name":"name","label":"Name","tooltip":"","group":"3a69d2ce.2e17be","order":2,"width":"6","height":"1","passthru":false,"mode":"text","delay":300,"topic":"{{msg.payload[0].name}}","x":949.5,"y":213,"wires":[["5993645e.a4326c"]]},{"id":"c2738d5b.83eb5","type":"ui_button","z":"aa98e43.bcd4418","name":"","group":"3a69d2ce.2e17be","order":17,"width":"4","height":"1","passthru":false,"label":"Save","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":358.5,"y":365,"wires":[["5993645e.a4326c"]]},{"id":"5993645e.a4326c","type":"change","z":"aa98e43.bcd4418","name":"2","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640.5,"y":371,"wires":[["73e2bdd0.904fa4"]]},{"id":"73e2bdd0.904fa4","type":"debug","z":"aa98e43.bcd4418","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","x":874.5,"y":375,"wires":[]},{"id":"c1295981.fb5958","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"usvstd","tz":""},{"id":"3a69d2ce.2e17be","type":"ui_group","z":"","name":"Inserare Logo","tab":"a8840ceb.2d6c6","order":4,"disp":true,"width":"12","collapse":false},{"id":"a8840ceb.2d6c6","type":"ui_tab","z":"","name":"USV","icon":"dashboard","order":1}]


#2

Have you gone to the flow's library and searched for 'sql' or 'crud'? and I seem to remember some threads in the last couple months about this.


#3

I don t have a problem with sql, i know how to do that. I don t know how to get text from the input text into a variable, this is my issue


#4

So have you looked at the various threds and flows and found none that will help you?


#5

You cannot 'get' its value from the text box.

The approach you should take is to use Flow Context to store the value where you can then retrieve it from anywhere else in your flow.

You can do this by wiring a Change node after the ui_text node to "set flow.foo to msg.payload"

Then you can use flow.foo else where in your flow (via Change node or Function node) to get its current value.


#6

Ok, I simplified the flow to exactly my issue. So the flow is :slight_smile:

[{"id":"cfc4cf05.25252","type":"tab","label":"Flow 10","disabled":false,"info":""},{"id":"d6c62f69.6a0ab","type":"ui_button","z":"cfc4cf05.25252","name":"","group":"a59b5a47.e196d8","order":32,"width":0,"height":0,"passthru":false,"label":"save","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":500,"y":393,"wires":[["1362df8e.d13b3"]]},{"id":"a81e7e43.881dc","type":"ui_text_input","z":"cfc4cf05.25252","name":"","label":"text","tooltip":"","group":"a59b5a47.e196d8","order":31,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"text","x":498,"y":308,"wires":[["1362df8e.d13b3","1bf73e07.5b49a2"]]},{"id":"1bf73e07.5b49a2","type":"debug","z":"cfc4cf05.25252","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":880,"y":358,"wires":[]},{"id":"1362df8e.d13b3","type":"function","z":"cfc4cf05.25252","name":"text","func":"var text = msg.payload ;\n\nmsg.payload = text;\n\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":392,"wires":[["1bf73e07.5b49a2"]]},{"id":"a59b5a47.e196d8","type":"ui_group","z":"","name":"Meniu Principal","tab":"a8840ceb.2d6c6","order":1,"disp":false,"width":"12","collapse":false},{"id":"a8840ceb.2d6c6","type":"ui_tab","z":"","name":"USV","icon":"dashboard","order":1}]

When I type in the text input I get what I type in debug console. That is because " If msg arrives on input, pass through to output:" option is checked.
But when I click save button I get

msg.payload : string[14]

"d6c62f69.6a0ab"

in the debug console. I am just not able to get that text into a variable...


#7

You need to store textinput in function context and use it when you save.

[{"id":"f75bd48b.f31218","type":"ui_button","z":"9492aff.e31d05","name":"","group":"39627b16.6f4254","order":32,"width":0,"height":0,"passthru":false,"label":"save","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"save","x":510,"y":400,"wires":[["bd27a3a5.f3c0c"]]},{"id":"c410bd71.4b1e7","type":"ui_text_input","z":"9492aff.e31d05","name":"","label":"text","group":"39627b16.6f4254","order":31,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"textinput","x":510,"y":320,"wires":[["bd27a3a5.f3c0c"]]},{"id":"abef5d31.9c6b5","type":"debug","z":"9492aff.e31d05","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":840,"y":320,"wires":[]},{"id":"bd27a3a5.f3c0c","type":"function","z":"9492aff.e31d05","name":"text","func":"var lastinput = context.get(\"lastinput\") || \"\";\n\nif(msg.topic === \"textinput\"){\n    lastinput = msg.payload;\n    context.set(\"lastinput\",lastinput);\n}\nif(msg.topic === \"save\"){\n    msg.payload = lastinput;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":380,"wires":[["abef5d31.9c6b5"]]},{"id":"39627b16.6f4254","type":"ui_group","z":"","name":"Meniu Principal","tab":"8bccc011.1774a","order":1,"disp":false,"width":"12","collapse":false},{"id":"8bccc011.1774a","type":"ui_tab","z":"","name":"USV","icon":"dashboard","order":1}]

#8

add a seperate debug node to each of your three nodes - this way when you hoverer an entry in the debug log, it will highlight the node it came from.

Type some text and look at the debug log then press the button and look at the debug log.

What do you see? What does it mean?