New barcode value gets added to the previous value. How to fix it?

Hello everyone,

I have a numeric entry field (field 1) in vision that takes a barcode scanner input. I configured that field to have focus. However, every time a new barcode value is entered it keeps added to the previous value!!
So for example, if my previous barcode value is 1234 and my new barcode is 5678, what I have in field 1 as a new barcode is 12345678. So when the barcode enters new value, I want to be able to store 1234 in another field (field 2) and then empty out field 1 for new barcode values.
Any idea how this can be done?

I have this script for focus on value change of field 1, I am guessing I have to add writeblocking script and empty out a script in the same property change section, correct?

if event.propertyName == "longValue":
     event.source.requestFocusInWindow()

Appreciate any information!

I recommend instead, when setting focus, also set the selection to all of the current content (using the field’s .selectAll() method). That makes further typing/scanning replace that content.

1 Like

Thank you! I am not quite sure how to apply selectAll() here in property change for this application. Could not find any information in the manual. Is this being done in perspective? I am using vision for this application.

No, it is for vision. Your code sample would look like this, perhaps:

if event.propertyName == "longValue":
     event.source.requestFocusInWindow()
     event.source.selectAll()

The method is not documented in Ignition because it is something standard in the Java Swing platform that Vision is built on.

1 Like

Thank you very much, Phil for the great information.
I tried that; however, as you probably see from the video.
I can scan the barcode into the field, the second time I scan, the value is added to the initial value, but the 3rd time the focus is on the whole field. SO the action does not work for the 2nd scan, 4th, 6th and so on but it is working for 3rd scan, 5th, 7th and so on…

In the video below, I first erased the field, scanned the first value, after that the 2nd, 3rd and 4th values. Only for the 3rd value I have the focus on the whole text field.

Might need to defer the selectAll for a few milliseconds. Like so:

if event.propertyName == "longValue":
     event.source.requestFocusInWindow()
     system.util.invokeLater(event.source.selectAll, 50)
1 Like

Interestingly, it is still the same as before, so I did not see any changes. I even changed the defer value but was not successful to make it working.