Focus on Text Box Loses Cursor

Good Morning,

I’m working in Perspective, Gateway 8.0.16.

I have a pretty basic setup where a menu item is clicked, and kicks off 2 events: 1) An Embedded View loads a new view, and 2) a Text Field is given focus.

The problem I’m having is that the Text Field is given focus properly half the time, and the other half, it is given focus (based on console messaging on the onFocus event and the outline around the component) but the cursor won’t be in the component. I can tell that focus wasn’t lost (because of console messaging on the onBlur event, and the outline on the component) but the cursor hasn’t moved to the Text Field.

Any thoughts on what could be stealing my cursor, or how to get it back while the Text Field has focus? Best guess is it’s a timing issue with the view loading, but I have put the focus call as late in the sequence as I can.

I’m using a message handler on the Text Field with the following code to give it focus:

self.focus()
system.perspective.print('focus given by message handler')

For anyone who is interested, I fixed the problem by adding a 1/4 second delay before calling focus to Text Field:

from time import sleep

sleep(.25)
self.focus()
system.perspective.print('focus given by message handler')

I’m not excited by this solution, but it seems to separate the loading of the new view in the Embedded View from the focus setting enough that they no longer fight each other and end up with the lost cursor.

I’d be interested in anyone else has a better reason or solution for this behavior.

1 Like