# Enabling and focusing a TextFeild on an event in Perspective

**URL:** <https://forum.inductiveautomation.com/t/enabling-and-focusing-a-textfeild-on-an-event-in-perspective/57646>\
**Category:** Ignition\
**Created:** [March 25, 2022, 2:36pm UTC](https://forum.inductiveautomation.com/t/enabling-and-focusing-a-textfeild-on-an-event-in-perspective/57646 "2022-03-25T14:36:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.inductiveautomation.com/u/user66)\
**Post date:** [March 25, 2022, 2:36pm UTC](https://forum.inductiveautomation.com/t/enabling-and-focusing-a-textfeild-on-an-event-in-perspective/57646/1 "2022-03-25T14:36:29Z")

</div>

I have a Disabled TextField component which should be enabled and on focus when I click on a button. The TextField becomes enabled but focus does not change on the first click.  
This is the script I have made:

```auto
self.getSibling("TextField").props.enabled=True
self.getSibling("TextField").focus()

```

Is there any way to achieve this functionality on single click?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 25, 2022, 2:45pm UTC](https://forum.inductiveautomation.com/t/enabling-and-focusing-a-textfeild-on-an-event-in-perspective/57646/2 "2022-03-25T14:45:45Z")

</div>

Where is that code executed?

Tip: use the `</>` code formatting button, not the `>` quotation button.

---

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.inductiveautomation.com/u/user66)\
**Post date:** [March 25, 2022, 2:54pm UTC](https://forum.inductiveautomation.com/t/enabling-and-focusing-a-textfeild-on-an-event-in-perspective/57646/3 "2022-03-25T14:54:15Z")

</div>

It’s run on ‘_onclick_’ event script of a button that I made near the TextField

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 25, 2022, 11:27pm UTC](https://forum.inductiveautomation.com/t/enabling-and-focusing-a-textfeild-on-an-event-in-perspective/57646/4 "2022-03-25T23:27:43Z")

</div>

I’d say there’s a delay on the view learning that the component is enabled and that the `focus()` command is fired before it’s ready.

```auto
	from time import sleep
	
	self.getSibling("TextField").props.enabled = True
	sleep(0.1)
	self.getSibling("TextField").focus()

```

works in Designer. I didn’t try it in a browser so you might need to test and increase the delay slightly.

This variation has the advantage of exiting as soon as possible and may feel a little more responsive but at the expense of five lines of code rather than the single `sleep()` instruction. A Python expert may be able to compress it for you.

```auto
	self.getSibling("TextField").props.enabled = True
	i = 0
	while i < 100:
		i += 1
		if self.getSibling("TextField").props.enabled == True:
			break
	self.getSibling("TextField").focus()

```

---

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.inductiveautomation.com/u/user66)\
**Post date:** [March 26, 2022, 3:50am UTC](https://forum.inductiveautomation.com/t/enabling-and-focusing-a-textfeild-on-an-event-in-perspective/57646/5 "2022-03-26T03:50:25Z")

</div>

> [@Transistor](#):
>
> ```auto
> from time import sleep
> 	
> self.getSibling("TextField").props.enabled = True
> sleep(0.1)
> self.getSibling("TextField").focus()
> 
> ```

This worked on browser 😀  
Thanks for that

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 26, 2022, 9:10am UTC](https://forum.inductiveautomation.com/t/enabling-and-focusing-a-textfeild-on-an-event-in-perspective/57646/6 "2022-03-26T09:10:58Z")

</div>

I believe something like this would work:

```python
any(self.getSibling("TextField").props.enabled for _ in xrange(timeout))

```

This would iterate until either `timeout` is reached or `[...].enabled` returns `True`
