# Input text focus

**URL:** <https://discourse.nodered.org/t/input-text-focus/76753>\
**Category:** Dashboard\
**Created:** [20 March 2023 14:14 UTC](https://discourse.nodered.org/t/input-text-focus/76753 "2023-03-20T14:14:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr\_Li](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mr_li/32/67089_2.png) [@Mr\_Li](https://discourse.nodered.org/u/Mr_Li)\
**Post date:** [20 March 2023 14:14 UTC](https://discourse.nodered.org/t/input-text-focus/76753/1 "2023-03-20T14:14:37Z")

</div>

> 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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7fccd50b19e02f83a7cd940c61a8d9a0cd97b738.png)

 ![22222](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/db6e6fe3470470b65c8f0864c835bcbe205f324c.png)  
 ![3333](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/28549f323973bdf1af4569dfd37daed86b91d72e.png)

```auto
[
    {
        "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
    }
]

```

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [20 March 2023 15:08 UTC](https://discourse.nodered.org/t/input-text-focus/76753/2 "2023-03-20T15:08:20Z")

</div>

Try this

```auto
[{"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}]

```

---

<div class="post-metadata">

**Author:** ![Mr\_Li](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mr_li/32/67089_2.png) [@Mr\_Li](https://discourse.nodered.org/u/Mr_Li)\
**Post date:** [20 March 2023 15:26 UTC](https://discourse.nodered.org/t/input-text-focus/76753/3 "2023-03-20T15:26:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 April 2023 15:27 UTC](https://discourse.nodered.org/t/input-text-focus/76753/4 "2023-04-03T15:27:05Z")

</div>

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