# Mouse enter event in Numeric text field

**URL:** <https://forum.inductiveautomation.com/t/mouse-enter-event-in-numeric-text-field/65562>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [October 22, 2022, 5:59am UTC](https://forum.inductiveautomation.com/t/mouse-enter-event-in-numeric-text-field/65562 "2022-10-22T05:59:21Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [October 22, 2022, 5:59am UTC](https://forum.inductiveautomation.com/t/mouse-enter-event-in-numeric-text-field/65562/1 "2022-10-22T05:59:21Z")

</div>

Hi,  
I would like to have a screen in which user can select a process and then a popup appears in which user can enter the target qty for today and tomorrow.

Script used in Upload screen (vision window open event):

```auto

tmp = system.gui.getParentWindow(event).getComponentForPath('Root Container.tmp_Rpt_plan')
planTemplate =system.gui.getParentWindow(event).getComponentForPath('Root Container.tmp_Rpt_plan').templateParams

newtmp =system.dataset.clearDataset(planTemplate)
vProcess = system.gui.getParentWindow(event).getComponentForPath('Root Container').Process

query =system.db.runPrepQuery("SELECT EquipmentName as 'MachineName' FROM cdcms.tbl_equipment where ProcessArea =?", [vProcess])
	
newtmp = system.dataset.addRows(newtmp,query)

tmp.templateParams=newtmp

```

For eg: when a user enters a value for today for machine 1 and clicks enter,  
it should get focus to the next machine's today text field.  
I dont know how to achieve this with key event. Any ideas on this?  
Thanks in advance

---

<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:** [October 22, 2022, 6:51am UTC](https://forum.inductiveautomation.com/t/mouse-enter-event-in-numeric-text-field/65562/2 "2022-10-22T06:51:06Z")

</div>

> [@Dharani\_T](#):
>
> clicks enter,  
> it should get focus to the next machine's today text field

Here is one possible approach: on the keypress event, get the next component and request focus based on the VK\_Enter keycode:

```auto
if event.keyCode == event.VK_ENTER:
	event.source.parent.getComponent('Numeric Text Field 1').requestFocus()
	#Substitute the next component and path for the component listed above

```

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [October 22, 2022, 6:59am UTC](https://forum.inductiveautomation.com/t/mouse-enter-event-in-numeric-text-field/65562/3 "2022-10-22T06:59:58Z")

</div>

As I am using template repeater, the count will vary for each process,

So I used the keypress event in the template, but IDK how to get the next component

---

<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:** [October 22, 2022, 7:22am UTC](https://forum.inductiveautomation.com/t/mouse-enter-event-in-numeric-text-field/65562/4 "2022-10-22T07:22:16Z")

</div>

I played around with trying to get the transversal policy, but I couldn't get it to work.

Try this code in the template, and see if it works:

```auto
if event.keyCode == event.VK_ENTER:
	for component in event.source.parent.getComponents():
		if component == event.source:
			currentComponent.requestFocus()
			break
		currentComponent = component

```

**Edit: This code works in a normal container, not in a template repeater**

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [October 22, 2022, 7:24am UTC](https://forum.inductiveautomation.com/t/mouse-enter-event-in-numeric-text-field/65562/5 "2022-10-22T07:24:14Z")

</div>

> [@justinedwards.jle](#):
>
> ```auto
> if event.keyCode == event.VK_ENTER:
> for component in event.source.parent.getComponents():
> if component == event.source:
> currentComponent.requestFocus()
> break
> currentComponent = component
> 
> ```

When I click enter, focus is moving on to adjacent text field not the next row component.

---

<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:** [October 22, 2022, 8:08am UTC](https://forum.inductiveautomation.com/t/mouse-enter-event-in-numeric-text-field/65562/6 "2022-10-22T08:08:20Z")

</div>

I set up a template repeater with numeric text fields, and I got this code to work on the template's keyPressed event handler:

```auto
if event.keyCode == event.VK_ENTER:
	requestFocus = False
	for component in event.source.parent.parent.getComponents():
		for subComponent in component.getComponents():
			currentComponent = subComponent
			break
		if requestFocus:
			currentComponent.requestFocus()
			break
		if currentComponent == event.source:
			requestFocus = True

```

**Edit: This code works on templates that only have one component.**

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [October 22, 2022, 8:38am UTC](https://forum.inductiveautomation.com/t/mouse-enter-event-in-numeric-text-field/65562/7 "2022-10-22T08:38:19Z")

</div>

Did you use two adjacent numeric fields?  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/4/346f517049983f9305a72799539f36f783e2d640.png)  
I have written the code on Field 1's key press event But it is not getting focus to next row field's focus?!

---

<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:** [October 22, 2022, 8:55am UTC](https://forum.inductiveautomation.com/t/mouse-enter-event-in-numeric-text-field/65562/8 "2022-10-22T08:55:50Z")

</div>

Here is the result I am getting:

[https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/c/7cac22fa9deb5603045abf14a37e3a5f700c90e9.mp4](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/c/7cac22fa9deb5603045abf14a37e3a5f700c90e9.mp4)
  
I type a number and press enter, and the focus moves to the next textbox in the template.

Here are my template repeater's properties:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/a/4a0ac767e1f77480dc3e57a4358bfccb54646aa0.png)

I did notice that if I did not have the numeric text field template physically open when applying scripting changes, the changes did not show up in the template repeater.

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [October 22, 2022, 9:00am UTC](https://forum.inductiveautomation.com/t/mouse-enter-event-in-numeric-text-field/65562/9 "2022-10-22T09:00:13Z")

</div>

Thank you.  
But i require functionality like when i enter value and click enter focus should go to next field not the adjacent one(similar to the excel)

---

<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:** [October 26, 2022, 6:06am UTC](https://forum.inductiveautomation.com/t/mouse-enter-event-in-numeric-text-field/65562/10 "2022-10-26T06:06:00Z")

</div>

> [@Dharani\_T](#):
>
> go to next field not the adjacent one(similar to the excel)

Understood, the template I was using before only had a single numeric text field and no alternate components. The template I'm using now has a label and two numeric text fields. I modified the code to take the name of the source text field into consideration when searching for the next component and this resolved the issue. The code must be applied to the keyPressed event handler of both numeric text fields for it to work in both columns of the template.

Here is the code:

```auto
if event.keyCode == event.VK_ENTER:
	requestFocus = False
	for component in event.source.parent.parent.getComponents():
		for subComponent in component.getComponents():
			if subComponent.name == event.source.name:
				currentComponent = subComponent
				break
		if requestFocus:
			currentComponent.requestFocus()
			break
		if currentComponent == event.source:
			requestFocus = True

```

Here is the result:

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [October 26, 2022, 6:09am UTC](https://forum.inductiveautomation.com/t/mouse-enter-event-in-numeric-text-field/65562/11 "2022-10-26T06:09:03Z")

</div>

Hi Justin,

Thank you so much for your efforts. It is working!!!
