Entering data by mouse click vs enter key

I have a dumb new guy question.

I have a global field (gpatient_name_for_lookup) that displays a valuelist of patient names. The field is assigned a value of ‘Select Patient’. Onfocusgained, I run a method to clear the field.

On data change I run the following script to lookup the patient.

controller.find()
lastname_firstname_city = globals.gpatient_name_for_lookup
var x = controller.search()

if(x == 0)
{
var btn = globals.Error_message(‘You did not select a Patient from the List’, ‘Try Again’);

if (btn == ‘Try Again’)
{
controller.loadAllRecords()
}
}
globals.gpatient_name_for_lookup = ‘Select Patient’

The method works perfectly when you select a name by typing and hitting the enter key, but does not work properly when you select a name from the list with the mouse.

With a mouse click, the method takes you to the right patient, but the global field quickly displays “Select Patient” then quickly drops the value list and then goes blank.

My best guess is that setting the global field to ‘Select Patient’ is causing the onfocusgained script to fire but I’m not sure how to fix it.

Any help would be appreciated. Thanks.

Carmen

onFocus is also triggered when the list is closed (the focus is transferred from the list to field component)
Same holds true for the dialog, when the dialog is closed you will get an onFocus event (because the focus is transferred from dialog to field component)

It think you just cannot use onFocus to clear a field (there are many focus transfers possible), selectOnEnter is somewhat similar and might be usable in this case.