# Auto Select Text Box on Start

**URL:** <https://forum.inductiveautomation.com/t/auto-select-text-box-on-start/52976>\
**Category:** Ignition\
**Tags:** ignition80, perspective\
**Created:** [November 11, 2021, 5:00pm UTC](https://forum.inductiveautomation.com/t/auto-select-text-box-on-start/52976 "2021-11-11T17:00:23Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![isabellapitco](https://avatars.discourse-cdn.com/v4/letter/i/ebca7d/32.png) [@isabellapitco](https://forum.inductiveautomation.com/u/isabellapitco)\
**Post date:** [November 11, 2021, 5:00pm UTC](https://forum.inductiveautomation.com/t/auto-select-text-box-on-start/52976/1 "2021-11-11T17:00:23Z")

</div>

Hi all,

As the title says, I’m trying to make it so that when a project view is opened the user can start typing directly into a text box without having to click on it first. I’ve been looking around and I haven’t been able to find anything yet. Does anyone have a suggestion on how to accomplish this?

Thanks!

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 11, 2021, 5:09pm UTC](https://forum.inductiveautomation.com/t/auto-select-text-box-on-start/52976/2 "2021-11-11T17:09:56Z")

</div>

> [@Perspective Request Focus in Window](https://forum.inductiveautomation.com/t/perspective-request-focus-in-window/26899):
>
> Hello, I tried to transfer one of my Vision projects to Perspective. I have android based scanner and 2 text fields where I want operators to scan Work Order Number and Part Number. In Vision, I just added script RequestFocusInWindow() and it works perfect, however the same script is not working in Perspective module. Am I missing something there or it is impossible. Best regards Pawel

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [November 11, 2021, 5:09pm UTC](https://forum.inductiveautomation.com/t/auto-select-text-box-on-start/52976/3 "2021-11-11T17:09:58Z")

</div>

virtual or physical keyboard?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [November 11, 2021, 5:13pm UTC](https://forum.inductiveautomation.com/t/auto-select-text-box-on-start/52976/4 "2021-11-11T17:13:30Z")

</div>

In the Startup Event of the component (or of the View), specify your Text Field and give it focus.

Startup Event of the Text Field:

```auto
self.focus()

```

Startup Event for the View:

```auto
# you'll need to drill down through the component hierarchy to locate your text field here
self.root.getChild("Text Field").focus()

```

---

<div class="post-metadata">

**Author:** ![isabellapitco](https://avatars.discourse-cdn.com/v4/letter/i/ebca7d/32.png) [@isabellapitco](https://forum.inductiveautomation.com/u/isabellapitco)\
**Post date:** [November 11, 2021, 5:24pm UTC](https://forum.inductiveautomation.com/t/auto-select-text-box-on-start/52976/5 "2021-11-11T17:24:37Z")

</div>

Thank you all! I knew it was simple and that the solution was out there but I was struggling with the search on the forum. Appreciate the response!

---

<div class="post-metadata">

**Author:** ![isabellapitco](https://avatars.discourse-cdn.com/v4/letter/i/ebca7d/32.png) [@isabellapitco](https://forum.inductiveautomation.com/u/isabellapitco)\
**Post date:** [November 11, 2021, 11:04pm UTC](https://forum.inductiveautomation.com/t/auto-select-text-box-on-start/52976/6 "2021-11-11T23:04:06Z")

</div>

Sorry to open this up again, but I’m having trouble getting focus() to work. It works perfectly when I tested it in an empty view w/just a text box, but I’m trying to incorporate it on a popup that also has other components. It doesn’t want to work no matter where I make the focus call. I’m not sure whether its because there’s other components that are loading after the call and that’s messing it up somehow, or if it has to do with the fact that it’s a popup and that’s confusing it somehow. Any advice?

---

<div class="post-metadata">

**Author:** ![swolnisty](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@swolnisty](https://forum.inductiveautomation.com/u/swolnisty)\
**Post date:** [November 12, 2021, 12:27am UTC](https://forum.inductiveautomation.com/t/auto-select-text-box-on-start/52976/7 "2021-11-12T00:27:10Z")

</div>

Are you using both of the suggestions that @cmallonee suggested? I believe the intent was that either of those events would do the job, but you probably should only be using one or the other.

---

<div class="post-metadata">

**Author:** ![isabellapitco](https://avatars.discourse-cdn.com/v4/letter/i/ebca7d/32.png) [@isabellapitco](https://forum.inductiveautomation.com/u/isabellapitco)\
**Post date:** [November 12, 2021, 12:50am UTC](https://forum.inductiveautomation.com/t/auto-select-text-box-on-start/52976/8 "2021-11-12T00:50:26Z")

</div>

No, just trying one at a time to see what works

---

<div class="post-metadata">

**Author:** ![swolnisty](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@swolnisty](https://forum.inductiveautomation.com/u/swolnisty)\
**Post date:** [November 12, 2021, 1:02am UTC](https://forum.inductiveautomation.com/t/auto-select-text-box-on-start/52976/9 "2021-11-12T01:02:21Z")

</div>

It’s hard to say why it’s not working without taking a look at the popup view itself. Is it possible that there is another component in the popup view calling focus() as well (e.g. if the original textfield that had your onStartup event was duplicated, but the event was not removed from the duplicate textfield)?

The fact that your textfield is contained within a popup should not matter though; I am using this method on a few different popups on some projects currently and it seems to work fairly reliably.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [November 12, 2021, 2:17pm UTC](https://forum.inductiveautomation.com/t/auto-select-text-box-on-start/52976/10 "2021-11-12T14:17:00Z")

</div>

If you could supply the View in question, I could take a look at it. The only reason I would expect this not to work is if the Popup were to open with any piece of itself outside the bounds of the viewport.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [November 16, 2021, 4:10pm UTC](https://forum.inductiveautomation.com/t/auto-select-text-box-on-start/52976/11 "2021-11-16T16:10:36Z")

</div>

The issue at play was a race condition between the Popup requesting focus and the execution of the onStartup Event code for the View and the Text Field. The following code placed into the onStartup Event of the popup View works in my environment, albeit after a one-second “pause”.

```auto
	def tf_focus():
		from time import sleep
		sleep(1)
		self.getChild("mfaToken").focus()
	system.util.invokeAsynchronous(tf_focus)

```
