# Focus on the textbox (blur)

**URL:** <https://forum.inductiveautomation.com/t/focus-on-the-textbox-blur/102033>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [February 7, 2025, 1:54pm UTC](https://forum.inductiveautomation.com/t/focus-on-the-textbox-blur/102033 "2025-02-07T13:54:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [February 7, 2025, 1:54pm UTC](https://forum.inductiveautomation.com/t/focus-on-the-textbox-blur/102033/1 "2025-02-07T13:54:44Z")

</div>

Hello everyone,

I need help with the following situation: I have a program running on a workstation where the user needs to scan parts. Because of this, the focus must remain on the text field. I am using the `Focus` and `onBlur` events so that whenever the user clicks outside the field, the focus is automatically returned to the text field.  
The station didn't have a keyboard the only interaction is by the touchscreen, the user can click on the buttons when needed.

The onBlur triggers a script as shown below.

```python
def tf_focus(self):
	view = self.view
	view.refreshBinding("custom.Parameters.vUserID") 
	view.refreshBinding("custom.Parameters.vUserName")
	def waitFocus():
		from time import sleep
		sleep(.25)
		vPath = 'root/FlexMain/FlexSerialInfo/'
		if vViewDowntimeActive == 0 or vScrapinHold == 0:
			view.getChild(vPath + "lvSerialNumber").props.enabled = True
			if view.getChild(vPath + "lvSerialNumber").focus() != True:
				view.getChild(vPath + "lvSerialNumber").focus()
		else:
			view.getChild(vPath + "lvSerialNumber").props.enabled = False
			
	system.util.invokeAsynchronous(waitFocus)

```

![textfied](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/e/4ec1e4e84dbd1daa9fd3cbec587cf2b55a4297e7.gif)

I was wondering if this is the best approach.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [February 7, 2025, 2:58pm UTC](https://forum.inductiveautomation.com/t/focus-on-the-textbox-blur/102033/2 "2025-02-07T14:58:39Z")

</div>

I wouldn't use `system.util.invokeAsynchronous` with `sleep`, I would do:

```python
from threading import Timer 

def waitFocus(self):
	view = self.view
	vPath = 'root/FlexMain/FlexSerialInfo/'
	if vViewDowntimeActive == 0 or vScrapinHold == 0:
		view.getChild(vPath + "lvSerialNumber").props.enabled = True
		if view.getChild(vPath + "lvSerialNumber").focus() != True:
			view.getChild(vPath + "lvSerialNumber").focus()
	else:
		view.getChild(vPath + "lvSerialNumber").props.enabled = False

def tf_focus(self):
	view = self.view
	view.refreshBinding("custom.Parameters.vUserID") 
	view.refreshBinding("custom.Parameters.vUserName")
	Timer(0.25, waitFocus, [self]).start()
	

```
