Input text focus

I am a novice in node-red, a barcode input binding project. I want to clear the barcode data by clicking the button and set the focus for the text field to reduce the click time. What should I do? I have been trying for several hours and still haven't succeeded. Please help me, thank you!

11111


[
    {
        "id": "10347ce3.586fb3",
        "type": "ui_button",
        "z": "d5e31309.28ca2",
        "name": "",
        "group": "9c9a39bf.1be348",
        "order": 2,
        "width": 2,
        "height": 1,
        "passthru": false,
        "label": "clean",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "buttona",
        "icon": "",
        "payload": "",
        "payloadType": "str",
        "topic": "",
        "topicType": "str",
        "x": 210,
        "y": 340,
        "wires": [
            [
                "2c849fb770fa722f"
            ]
        ]
    },
    {
        "id": "a0afafc2f94aa44c",
        "type": "ui_text_input",
        "z": "d5e31309.28ca2",
        "name": "",
        "label": "Barcode_1",
        "tooltip": "",
        "group": "9c9a39bf.1be348",
        "order": 1,
        "width": 6,
        "height": 1,
        "passthru": true,
        "mode": "text",
        "delay": 300,
        "topic": "topic",
        "sendOnBlur": true,
        "className": "myclass_clean",
        "topicType": "msg",
        "x": 590,
        "y": 340,
        "wires": [
            []
        ]
    },
    {
        "id": "ab777a166bc90d1e",
        "type": "ui_template",
        "z": "d5e31309.28ca2",
        "group": "9c9a39bf.1be348",
        "name": "test",
        "order": 10,
        "width": 0,
        "height": 0,
        "format": "<script>\n  action = function(){\n  document.getElementById('myclass_clean').focus();\n  }\n</script>\n<md-button onclick= 'action()'>\n<style>\n  [node-id='87cecd4991652066'] {\n    onclick='action()';\n  }\n\n<style>\n",
        "storeOutMessages": true,
        "fwdInMessages": true,
        "resendOnRefresh": true,
        "templateScope": "local",
        "className": "",
        "x": 490,
        "y": 300,
        "wires": [
            []
        ]
    },
    {
        "id": "98887f3e0df97d45",
        "type": "ui_text_input",
        "z": "d5e31309.28ca2",
        "name": "",
        "label": "Barcode_2",
        "tooltip": "",
        "group": "9c9a39bf.1be348",
        "order": 3,
        "width": 6,
        "height": 1,
        "passthru": true,
        "mode": "text",
        "delay": 300,
        "topic": "topic",
        "sendOnBlur": true,
        "className": "myclass_clean",
        "topicType": "msg",
        "x": 590,
        "y": 380,
        "wires": [
            []
        ]
    },
    {
        "id": "87cecd4991652066",
        "type": "ui_button",
        "z": "d5e31309.28ca2",
        "name": "",
        "group": "9c9a39bf.1be348",
        "order": 4,
        "width": 2,
        "height": 1,
        "passthru": false,
        "label": "clean",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "buttona",
        "icon": "",
        "payload": "",
        "payloadType": "str",
        "topic": "",
        "topicType": "str",
        "x": 210,
        "y": 380,
        "wires": [
            [
                "0e280b9d6c732bb5"
            ]
        ]
    },
    {
        "id": "2c849fb770fa722f",
        "type": "change",
        "z": "d5e31309.28ca2",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 370,
        "y": 340,
        "wires": [
            [
                "a0afafc2f94aa44c"
            ]
        ]
    },
    {
        "id": "0e280b9d6c732bb5",
        "type": "change",
        "z": "d5e31309.28ca2",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 370,
        "y": 380,
        "wires": [
            [
                "98887f3e0df97d45"
            ]
        ]
    },
    {
        "id": "9c9a39bf.1be348",
        "type": "ui_group",
        "name": "Group1",
        "tab": "de7542ce.e7d19",
        "order": 2,
        "disp": true,
        "width": 8,
        "collapse": false
    },
    {
        "id": "de7542ce.e7d19",
        "type": "ui_tab",
        "name": "Tab1",
        "icon": "dashboard",
        "order": 31
    }
]

Try this

[{"id":"f4e479ac02c5690e","type":"ui_template","z":"09deee63c1b960f7","group":"c7a27394.057878","name":"","order":5,"width":0,"height":0,"format":"<script>\n    (function(scope) {\n  scope.$watch('msg', function(msg) {\n    if (msg) {      \n      $(\".input-\"+msg.payload).find('input')[0].value = \"\"\n      $(\".input-\"+msg.payload).find('input').focus()\n      \n    }\n  });\n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":460,"y":3180,"wires":[[]]},{"id":"9f3b2d75554a2006","type":"ui_text_input","z":"09deee63c1b960f7","name":"","label":"Input 1","tooltip":"","group":"c7a27394.057878","order":4,"width":0,"height":0,"passthru":false,"mode":"text","delay":300,"topic":"topic","sendOnBlur":true,"className":"input-1","topicType":"msg","x":450,"y":3240,"wires":[[]]},{"id":"0097dce8c469dc8d","type":"ui_button","z":"09deee63c1b960f7","name":"","group":"c7a27394.057878","order":6,"width":0,"height":0,"passthru":false,"label":"clear","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"1","payloadType":"str","topic":"topic","topicType":"msg","x":270,"y":3240,"wires":[["f4e479ac02c5690e"]]},{"id":"96c1f415b3441342","type":"ui_button","z":"09deee63c1b960f7","name":"","group":"c7a27394.057878","order":6,"width":0,"height":0,"passthru":false,"label":"clear","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"2","payloadType":"str","topic":"topic","topicType":"msg","x":270,"y":3280,"wires":[["f4e479ac02c5690e"]]},{"id":"3ed9d5116728df09","type":"ui_text_input","z":"09deee63c1b960f7","name":"","label":"Input 2","tooltip":"","group":"c7a27394.057878","order":4,"width":0,"height":0,"passthru":false,"mode":"text","delay":300,"topic":"topic","sendOnBlur":true,"className":"input-2","topicType":"msg","x":450,"y":3280,"wires":[[]]},{"id":"c7a27394.057878","type":"ui_group","name":"aha","tab":"54e197d8.7f7fe8","order":2,"disp":false,"width":"9","collapse":false,"className":""},{"id":"54e197d8.7f7fe8","type":"ui_tab","name":"key","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
3 Likes

God, I didn't expect an answer so soon. Thank you very much

1 Like

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