Mouse enter event in Numeric text field

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):


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

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

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

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

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:

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

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

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

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.

Did you use two adjacent numeric fields?
image
I have written the code on Field 1's key press event But it is not getting focus to next row field's focus?!

Here is the result I am getting:


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:

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.

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)

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:

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:

1 Like

Hi Justin,

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

1 Like