Hi, I’m fairly new to ignition and its expression scripting and need some advice on this… pls and ty
I’ve created a container to have a field text and a password field text for the user to input values and be able to switch users. Currently I have this working and once the user has typed in the correct details, a button performs the action to switc users in the client.
However, instead of having only the button, I’d like the user to be able to press the ENTER KEY on the keyboard to execute the user switch. I’ve tried to put the following code on the password field text’s event handlers of ketTyped (i’ve also tried it on propertyChange, mutually exclusive ofcourse, not at the same time).
if event.keyCode == event.VK_ENTER: #This script would go on a button in a popup window used to switch users without logging out of the client. # Pull the username and password from the input components uname = event.source.parent.getComponent("Username").text pwd = event.source.parent.getComponent("Password").text # Call switchUser. The event object is passed to this # function so that if the username and password work, # this window will be closed before the switch occurs. success= system.security.switchUser(uname,pwd,event) # If the login didn't work, give input focus back to the # username component, so that the user can try again if not success: event.source.parent.getComponent("Username").requestFocusInWindow()
However, running in vision client, im now unable to type in this field. the first key i press (Regardless of
which key) i get the error:
File "<event:keyTyped>", line 11, in <module> NameError: name 'uname' is not defined
Eventhough it executes perfectly find as is as a button (without the if event.keycode statement)
Thank you in advance