issue with controller.focusField

Hi,

I have a field on a form that triggers a method when focus is gained, called onFocusGained(). I also have a method on the form that is triggered when the form is loaded, called onLoad().

Inside the onLoad() method I am calling controller.focusField(myfield,false) because I would like my field to get the focus immediately on startup. However, the field does not appear to be getting the focus and the onFocusGained() method is not getting called. I do know that onLoad() is executing because I put info dialogs at the start and end of the method.

Any ideas why focusField isn’t working? I’m on Servoy 5.1.

Thanks,
Rick

One other thing to note. I verified the “name” property of the field is populated and matches the first parameter in my call to focusField.

if you put info dialogs at the beginning or the end, than indeed, your onFocusRequest get lost!!
Don’t do anything else, after you do: onFocusRequest…

what happens if you do it in onshow?
(dont you want it also for a reshow of the form anyway?, else use the firsttime boolean that onshow gets)

I have removed the dialogs except from the onFocusGained() method. Still no luck. I also tried calling onLoad() from the onShow event. That didn’t work either.

It seems that focusField() just isn’t working at all, no matter where or how I call it.

I just tried elements.myfield.requestFocus(true) and that worked as expected.

Anybody know why this works, but focusField does not? To me it seems like they should do almost exactly the same thing.

how do you exactly call focusFied?
it expect to get the fieldname as a string, not the actual field itself.

I am currently using:

controller.focusField("myfield",false);

I have also tried:

controller.focusField(myfield,false);

… and I’ve used true instead of false. That’s every variation I could think of.

The one with a string is the right one
And the true or false just says if it must skip readonly or not.

if you call that method that calls that focusField from a button does it then work?
Are you sure it is the right name?

This is odd. Before creating the button for the test you suggested, I deleted the field and re-created it. Then I added the button and called focusField from there, and it worked. I also then re-added the call to focusField in the onShow on the form, and it works now too!

I had triple-checked the name of the field before deleting it, so I really don’t think that was the issue. I’m thinking something must have been “messed up” behind the scenes and deleting/recreating the field fixed it.