# Another Perspective focus() question

**URL:** <https://forum.inductiveautomation.com/t/another-perspective-focus-question/52479>\
**Category:** Ignition\
**Tags:** ignition81, scripting, perspective\
**Created:** [October 28, 2021, 8:17pm UTC](https://forum.inductiveautomation.com/t/another-perspective-focus-question/52479 "2021-10-28T20:17:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [October 28, 2021, 8:17pm UTC](https://forum.inductiveautomation.com/t/another-perspective-focus-question/52479/1 "2021-10-28T20:17:03Z")

</div>

I’ve got a view that is used as an embedded view on a “main” view. The purpose of this view is to allow the operator to enter work order (Int8), part number (string), and quantity (int4) values. The values are all input as strings in a text field component (they are validated and converted to the proper data type elsewhere). The entry can be via manual input or barcode scan. Once entered a button is pressed to validate the data and set view parameters as required. Since the same embedded view is used to enter all 3 data values, I clear the text field and try to set the focus back on that component. Here is what I am doing:  
onStartup event script for the embedded view:

```auto
	system.perspective.sendMessage("focus", payload={'source': 'onStartup'}, scope="view")
	self.session.custom.valueEntryType = self.params.mode

```

the “focus” message handler:

```auto
	import util
	ln = 'valEnt_focus'
	session = self.session
	if 'source' in payload.keys():
		source = payload['source']
	else:
		source = 'UNKNOWN'
	util.log(ln, 'Focus Message Handler called from %s.' %(source), session)
	txtManual = self.getChild("flex_manual").getChild("txt_manual")
	txtManual.props.text = ''
	txtManual.focus()

```

On startup this seems to work OK. The text field gets the focus and an operator can simply start typing in the Work Order number.  
After clicking the “submit” button, I process the WO number and call the “focus” message handler again, but this does NOT re-focus on the text field.  
I’m calling this from a Project Library script and the message hander is being executed as I see the resulting log entry.  
Here is the library script’ relevant code:

```auto
	payload['source'] = 'setWorkOrder'
	system.perspective.sendMessage('focus', payload=payload, scope='session')

```

The message handler is configured for all 3 scopes (session, page, and view)  
The resulting log entry from the message handler script looks like I’d expect:

```auto
Focus Message Handler called from setWorkOrder.

```

One thing to note. I’m running this session in Chrome and have the Gateway Log page on a separate tab in the same browser session. After I’ve entered the WO and pressed submit (and the text field did NOT re-focus), if I go to the Gateway Log tab to check the log message, when I tab back to the Perspective session, the text field is focused.

Any ideas what I’m doing wrong here?
