# Focus on Text Box in Embedded view does not fire

**URL:** <https://forum.inductiveautomation.com/t/focus-on-text-box-in-embedded-view-does-not-fire/54286>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [December 19, 2021, 7:22pm UTC](https://forum.inductiveautomation.com/t/focus-on-text-box-in-embedded-view-does-not-fire/54286 "2021-12-19T19:22:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefan.marcin74](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@stefan.marcin74](https://forum.inductiveautomation.com/u/stefan.marcin74)\
**Post date:** [December 19, 2021, 7:22pm UTC](https://forum.inductiveautomation.com/t/focus-on-text-box-in-embedded-view-does-not-fire/54286/1 "2021-12-19T19:22:02Z")

</div>

Coming from # [Focus on Text Box Loses Cursor](https://forum.inductiveautomation.com/t/focus-on-text-box-loses-cursor/47476) - is there any better solution then specifying Sleep function ? Its the worst way to solve problem like this. Or can anyone explain what the flow of execution of scripts in embedded view so the sleep can actually be considered as good practice here ?

To explain the problem really short: We have a Page with a button which triggers a View in this view there is an embedded component in which is text input. This text input should be focused when the View loads. But except adding sleep to the embedded component to focus the cursor, we could not get it work.

Thanks.

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [December 20, 2021, 12:33am UTC](https://forum.inductiveautomation.com/t/focus-on-text-box-in-embedded-view-does-not-fire/54286/2 "2021-12-20T00:33:50Z")

</div>

I think ones I read that the instant script flow control is asynchronous, and you can not really control the order of execution.

Have you tried to set focus in _onStartup_ event? I would try to put the script in the view or in the component itself.

Regarding the _sleep_ action, I would use instead:

```auto
from threading import Timer
def focus():
     self.focus()
Timer(0.5, focus).start()

```

---

<div class="post-metadata">

**Author:** ![stefan.marcin74](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@stefan.marcin74](https://forum.inductiveautomation.com/u/stefan.marcin74)\
**Post date:** [December 20, 2021, 10:46am UTC](https://forum.inductiveautomation.com/t/focus-on-text-box-in-embedded-view-does-not-fire/54286/3 "2021-12-20T10:46:58Z")

</div>

Thanks but I am looking for some other way, e.g. checking if Component exists, or something similar to javascript like onDocumentReady. Stopping time or waiting certain amount of time would resolve to unexpected behavior I guess.

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [December 20, 2021, 2:41pm UTC](https://forum.inductiveautomation.com/t/focus-on-text-box-in-embedded-view-does-not-fire/54286/4 "2021-12-20T14:41:09Z")

</div>

As I told you have you tried to place the script on **onStartup** event?. Do it on the component itself.

```auto
self.focus()

```

or do it in a view script

```auto
try:
    self...focus()
except:
    pass

```

for me it works great, without any timer  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/2/621d0b75a74824f9ed5090c688f3a360c28bfde8.png)

---

<div class="post-metadata">

**Author:** ![stefan.marcin74](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@stefan.marcin74](https://forum.inductiveautomation.com/u/stefan.marcin74)\
**Post date:** [December 23, 2021, 10:38pm UTC](https://forum.inductiveautomation.com/t/focus-on-text-box-in-embedded-view-does-not-fire/54286/5 "2021-12-23T22:38:52Z")

</div>

We tried that but did not work, remember its an embedded view

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [December 23, 2021, 11:28pm UTC](https://forum.inductiveautomation.com/t/focus-on-text-box-in-embedded-view-does-not-fire/54286/6 "2021-12-23T23:28:16Z")

</div>

How if you give focus to the embedded view first and then give focus to component inside

---

<div class="post-metadata">

**Author:** ![stefan.marcin74](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@stefan.marcin74](https://forum.inductiveautomation.com/u/stefan.marcin74)\
**Post date:** [December 24, 2021, 10:12am UTC](https://forum.inductiveautomation.com/t/focus-on-text-box-in-embedded-view-does-not-fire/54286/7 "2021-12-24T10:12:32Z")

</div>

Nope, does not work, I tried this

This is embedded view - onStartup script  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/a/aa2b47cbb2f1e04d31bf6b397f1baf2b4694ca5c.png)

and this is component inside embedded view I want to have focused

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/8/082e4417b50ed62b1117df1a2d765bb8548c15c4.png)

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [December 25, 2021, 6:19am UTC](https://forum.inductiveautomation.com/t/focus-on-text-box-in-embedded-view-does-not-fire/54286/8 "2021-12-25T06:19:37Z")

</div>

Then use the timer [Focus on Text Box in Embedded view does not fire - #2 by jespinmartin1](https://forum.inductiveautomation.com/t/focus-on-text-box-in-embedded-view-does-not-fire/54286/2), that won’t harm anyone.
