# \[IGN-8732\] NumericEntryField.focus() Not Working

**URL:** <https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 3, 2023, 7:22pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994 "2023-10-03T19:22:02Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Wilson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nick_wilson/32/80663_2.png) [@Nick\_Wilson](https://forum.inductiveautomation.com/u/Nick_Wilson)\
**Post date:** [October 3, 2023, 7:22pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/1 "2023-10-03T19:22:02Z")

</div>

Hello,

I have a flex repeater that contains instances of a view that displays a certain type of entry field depending on some JSON that it's reading. For instance, if an object has Item["Input"] == "Number", then a NumericEntryField is displayed. If Item["Input"] == "Text", then a TextField is displayed.

I have a property change script on the value property of each kind of input component:

```auto
	if (currentValue > 0) and (len(str(currentValue)) > 0):
		if self.view.params.Index == self.view.params.dataLength:
			newIndex = 0
		else:
			newIndex = self.view.params.Index + 1
		system.perspective.sendMessage("InputElementFocus", {"index": newIndex})
		self.view.params.MeasuredValue = self.props.value
		self.props.style.backgroundColor = "#555555"

```

This change script sends a message to the parent Flex Repeater which tells it to focus on the next instance. This works for all components (TextField, Dropdown) except for the NumericEntryField. Here's the message handler that I have on the parent view:

```auto
	index = payload["index"]
	if self.view.params.Index == index:
		if self.view.params.Input == "Text":
			child = "TextField"
		elif self.view.params.Input == "Choice":
			child = "Dropdown"
		elif self.view.params.Input == "Number":
			child = "NumericEntryField"
		self.getChild("FlexContainer").getChild("FlexContainer").getChild(child).focus()
		self.getChild("FlexContainer").getChild("FlexContainer").getChild(child).props.style.backgroundColor = "#000000"

```

When the focus is set to an instance with a NumericEntryField, the NumericEntryField is focused on for a fraction of a second. The spinner displays, and then goes away. After this, there is no longer focus on any of the elements. The user has to click on the NumericEntryField before entering data.

Here's how the components / views are arranged in the Project Browser:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/7/278c670e4e7af5ee80bb48b97fa1bec27a5d9002.png)

Any help would be appreciated - thanks.

---

<div class="post-metadata">

**Author:** ![Joshua\_Benjamin](https://avatars.discourse-cdn.com/v4/letter/j/e56c9b/32.png) [@Joshua\_Benjamin](https://forum.inductiveautomation.com/u/Joshua_Benjamin)\
**Post date:** [October 4, 2023, 10:03pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/2 "2023-10-04T22:03:00Z")

</div>

Hello Nick,

I would recommend reaching out to our support department at [support@inductiveautomation.com](mailto:support@inductiveautomation.com) to open up a ticket for this particular issue.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [November 16, 2023, 10:42pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/3 "2023-11-16T22:42:50Z")

</div>

Nick,  
have you had any success with this?

I did two tests, neither work at all.

I have button that is supposed to set the focus on a numeric entry field:

```auto
self.parent.parent.getChild("FlexContainer_2").getChild("QtyLeft_1").focus()

```

Then I tried sending a message:

```auto
message = "get_focus_qtyLeft"
payload = ""
system.perspective.sendMessage(messageType = message, payload = payload)

```

```auto
def onMessageReceived(self, payload):
	self.focus()

```

Neither work. I'm sure I got something like this to work elsewhere in this project, but it may have been a text field.

---

<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 20, 2023, 4:38pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/4 "2023-11-20T16:38:34Z")

</div>

I just verified this script works on a Button:

```auto
self.getSibling("NumericEntryField").focus()

```

Verify your script isn't failing in some manner by checking your Gateway logs.

---

<div class="post-metadata">

**Author:** ![Nick\_Wilson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nick_wilson/32/80663_2.png) [@Nick\_Wilson](https://forum.inductiveautomation.com/u/Nick_Wilson)\
**Post date:** [November 20, 2023, 8:00pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/5 "2023-11-20T20:00:18Z")

</div>

The issue happens when self.getSibling("NumericEntryField").focus() is being called while the focus is on a TextField component. My issue, specifically, is when the focus is set by a message handler that's called by a property change script on the TextField's "text" property. I had a call with Joshua following his post above and we weren't able to get it working. Here's a gif of the issue - you can see that the property change script works when focusing from the NumericEntryField to the TextField, but not vise-versa.

![2023-11-20 14-53-47 (1)](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/d/7dc15514dbb3e7e01f8d8efef0caeb95b74212ec.gif)

---

<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 20, 2023, 9:12pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/6 "2023-11-20T21:12:11Z")

</div>

The Text Field piece is the key. The Message Handler route works as expected from other components, but something about the way the Text Field handles a commit of the value causes the issue. I'll open a new ticket to get it looked at.

As a workaround, introducing any sort of sleep before trying to apply focus to the Numeric Entry Field results in it working as expected.

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	from time import sleep
	sleep(.25)
	self.getSibling("NumericEntryField").focus()

```

---

<div class="post-metadata">

**Author:** ![Nick\_Wilson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nick_wilson/32/80663_2.png) [@Nick\_Wilson](https://forum.inductiveautomation.com/u/Nick_Wilson)\
**Post date:** [November 20, 2023, 9:21pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/7 "2023-11-20T21:21:22Z")

</div>

> [@cmallonee](#):
>
> ```auto
> from time import sleep
> sleep(.25)
> self.getSibling("
> 
> ```

This will work for now, much appreciated!

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [November 21, 2023, 7:39pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/8 "2023-11-21T19:39:34Z")

</div>

Nick, did you use a change script on both input boxes?

I just setup a numeric box and text box, placed a change script to set the focus on the other box, and after I type in one box, click outside, the focus moves to the other. This works both ways without a message handler.

---

<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 21, 2023, 8:15pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/9 "2023-11-21T20:15:24Z")

</div>

Clicking outside of a field didn't always result in the issue being seen. Pressing Enter resulted in the issue 100% of the time. Even Tab was hit-and-miss depending on if the Numeric Entry Field was before or after the Text Field.

---

<div class="post-metadata">

**Author:** ![Nick\_Wilson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nick_wilson/32/80663_2.png) [@Nick\_Wilson](https://forum.inductiveautomation.com/u/Nick_Wilson)\
**Post date:** [November 21, 2023, 8:18pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/10 "2023-11-21T20:18:48Z")

</div>

Yes, I have a change script on both boxes. The end-user of my application is given a repeater of input field instances - some of which are Numeric Entry Fields, and some of which are TextFields. These each have their own index, and are supposed to receive focus via a message handler when the value change script runs upon the "Enter" key press. I wanted to avoid them having to using a mouse to change focus, and was requested to make this work without the end-user having to press the Tab key.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [November 21, 2023, 8:47pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/11 "2023-11-21T20:47:19Z")

</div>

Dang, imagine life without the Tab key...

---

<div class="post-metadata">

**Author:** ![Luis\_Perez1](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Luis\_Perez1](https://forum.inductiveautomation.com/u/Luis_Perez1)\
**Post date:** [December 7, 2023, 3:15pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/12 "2023-12-07T15:15:09Z")

</div>

> [@cmallonee](#):
>
> `from time import sleep`

perfect 🙂 thank you!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 7, 2023, 3:27pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/13 "2023-12-07T15:27:56Z")

</div>

> [@Luis\_Perez1](#):
>
> perfect

_ **Cringe** _

Sleeping is necessary in some corner cases, but writing "perfect" for that import implies it is widely applicable. In many places in Ignition, it is like a hand grenade. (All kinds of related discussions on this forum.)

---

<div class="post-metadata">

**Author:** ![Luis\_Perez1](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Luis\_Perez1](https://forum.inductiveautomation.com/u/Luis_Perez1)\
**Post date:** [December 7, 2023, 3:39pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/14 "2023-12-07T15:39:29Z")

</div>

Perfect Perfect Perfect for me. Nothing will squash my excitement!

have a good one!

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 8, 2023, 5:56am UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/15 "2023-12-08T05:56:39Z")

</div>

> [@Luis\_Perez1](#):
>
> squash

When somebody states that they are going to optimize some code, there can be some ambiguity in what they actually mean. Are they optimizing for performance? ...for memory usage? ...for power consumption?

...but that said: you can take for granted that they aren't talking about implementing `sleep`.

---

<div class="post-metadata">

**Author:** ![Luis\_Perez1](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Luis\_Perez1](https://forum.inductiveautomation.com/u/Luis_Perez1)\
**Post date:** [December 8, 2023, 1:39pm UTC](https://forum.inductiveautomation.com/t/ign-8732-numericentryfield-focus-not-working/79994/16 "2023-12-08T13:39:05Z")

</div>

Someone needs to chill....
