Auto Advance Entry Field Focus in Perspective

Hello everyone,

I am new to perspective and I am trying to shift focus to different numeric entry fields:
So I have 5 numeric fields for 5 barcode values. Is it possible to shift the focus to the next field in such a way where there would be 5 separate scans displayed?
image

I found a property change script here:

But it does not work for perspective, I know there might be lots of ways to do that probably using containers or property changes, but not sure how to do it. Any information would be much appreciated!

Try this
https://docs.inductiveautomation.com/display/DOC80/Perspective+Component+Methods#PerspectiveComponentMethods-RequestingFocus

1 Like

Thank you very much for your response!
Unfortunately, I am not quite sure how to use the information provided in this link to find the answer. In order to advance focus, do I need to create a custom method for each numeric field? and then call them from somewhere else? Where should I use the focus command?

This is my first application with perspective so I am not quite sure to use which method exactly. I could not find anything for perspective and I found this link for vision:

You would do something similar to that vision script, but instead you would attach a property change event
script to the props.text prop of each input field and use this as the script:

if chr(13) in currentValue.value or chr(10) in event.newValue:
    self.getSibling('next input component').focus()

You can select the next input component from the property selector. You can’t select a component itself, so you’ll need to select a property of a component and then delete the property name text so you’re left with similar to above code

2 Likes

I am not quite sure what is chr(13) and chr(10). Are they being used only for text fields? Or I can use them for numeric field as well? My application has only numeric fields.

Also, I tried this code, and it did not work.

So what I did was:

  1. Created 2 text fields
  2. Used edit property change script on the first field
  3. I wrote this script:
	if chr(13) in currentValue.value or chr(10) in event.newValue:
	    self.getSibling("TextField_0").focus()

I did the same thing for two numeric fields although I was not sure if I can use the same script, it did not work either. So when the barcode scanner enters the 1st value, the cursor does not automatically go to the 2nd field.

This is what I did and it worked:

  1. Created 2 text fields (tx0, tx1)
  2. Used edit property change script on the first field (tx0)
  3. I wrote this script:
	if currentValue!=previousValue:
	    self.getSibling('tx1').focus()

Chr(13) is tab and ch(10) is carriage return* (or line feed… Can’t remember), which are usually what a bar code scanner uses to delimit the end of its code. Glad you got it sorted

1 Like

Chr(13) is Carriage Return, also written as \r.
Chr(10) is Line Feed or New Line, also written as \n

1 Like

Whoops! I knew that, tab is chr(9)

1 Like

Thank you! Could not have done it without your help.

Thanks for the clarification!