issue with controller.focusField

Questions, tips and tricks and techniques for scripting in Servoy

issue with controller.focusField

Postby rlane » Wed May 05, 2010 10:15 pm

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
rlane
 
Posts: 11
Joined: Tue Apr 13, 2010 9:39 pm

Re: issue with controller.focusField

Postby rlane » Wed May 05, 2010 10:18 pm

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.
rlane
 
Posts: 11
Joined: Tue Apr 13, 2010 9:39 pm

Re: issue with controller.focusField

Postby Harjo » Wed May 05, 2010 11:38 pm

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...
Harjo Kompagnie
byKom B.V.
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: issue with controller.focusField

Postby jcompagner » Thu May 06, 2010 10:55 am

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)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8884
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: issue with controller.focusField

Postby rlane » Thu May 06, 2010 1:59 pm

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.
rlane
 
Posts: 11
Joined: Tue Apr 13, 2010 9:39 pm

Re: issue with controller.focusField

Postby rlane » Thu May 06, 2010 2:23 pm

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.
rlane
 
Posts: 11
Joined: Tue Apr 13, 2010 9:39 pm

Re: issue with controller.focusField

Postby jcompagner » Thu May 06, 2010 3:25 pm

how do you exactly call focusFied?
it expect to get the fieldname as a string, not the actual field itself.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8884
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: issue with controller.focusField

Postby rlane » Thu May 06, 2010 3:31 pm

I am currently using:

Code: Select all
controller.focusField("myfield",false);


I have also tried:

Code: Select all
controller.focusField(myfield,false);


... and I've used true instead of false. That's every variation I could think of.
rlane
 
Posts: 11
Joined: Tue Apr 13, 2010 9:39 pm

Re: issue with controller.focusField

Postby jcompagner » Thu May 06, 2010 3:58 pm

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?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8884
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: issue with controller.focusField

Postby rlane » Thu May 06, 2010 8:04 pm

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.
rlane
 
Posts: 11
Joined: Tue Apr 13, 2010 9:39 pm


Return to Methods

Who is online

Users browsing this forum: Bing [Bot] and 5 guests