onElementFocusGained fails on labels

Questions, tips and tricks and techniques for scripting in Servoy

onElementFocusGained fails on labels

Postby maria » Mon Sep 19, 2011 4:31 am

Hi!

I'm not sure if onElementFocusGained is supposed to be fired on labels but as long as it is a form event I assumed that it is.
Well, it's not in my solution. I was wondering if it's a bug or not. Because I want it to fire on any element of the form which gains focus.

Thank you!

Cheers,
Maria

P.S. A sample solution with the failing event is attached just in case. Click on the textfield - console comes up with a mesage. Click on the label next to it - nothing happens.
Attachments
elementFocusFails.servoy
(3.82 KiB) Downloaded 293 times
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: onElementFocusGained fails on labels

Postby jcompagner » Mon Sep 19, 2011 11:14 am

only fields do get focus events, labels don't get focus.
Also in the designer you don't have the focus events on a label, only on fields.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: onElementFocusGained fails on labels

Postby maria » Tue Sep 20, 2011 3:21 am

jcompagner wrote:only fields do get focus events, labels don't get focus.
Also in the designer you don't have the focus events on a label, only on fields.


True, but in designer we can use onAction on a label.

See, my problem is this: we have multiple windows in our application and I keep track of each window's data environment. When changes happen to data I must know exactly in which window they are happening.
This is why I need to have a base method in the base form from which everything else is inheriting, that will always keep track of the active window. That is, when I'm changing the data in window 'A' and then click on a 'search' label, for example, in window 'B', I need a way of knowing it happened and switch the active window variable to the appropriate window. I did it in onRecordEditStart (before it came to labels) and it worked well until I found myself in a scenario where no data change happens on a label click but later in the code I need to have switched the active window to the one with that label and it didn't happen because onRecordEditStart hasn't fired and onElementFocusGained doesn't work on labels.

Perhaps it's a little complicated, but anyway, is there a chance that onElementFocusGained will be working on other elements than fields?
Otherwise, how do I determine the moment another window got focus?

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: onElementFocusGained fails on labels

Postby jcarlos » Tue Sep 20, 2011 4:35 am

maria wrote:See, my problem is this: we have multiple windows in our application and I keep track of each window's data environment. When changes happen to data I must know exactly in which window they are happening.


I am writing this from my iPhone so I have to be short.

If I were you, I used a global such as

var windowsenvironment = ""; 

I'd then use this to identify the base form (by the form name perhaps). The global could be set on show form property - maybe. 

Hope this help. Best, Carlos
jcarlos
 
Posts: 578
Joined: Thu May 04, 2006 8:55 pm
Location: Palo Alto, California USA

Re: onElementFocusGained fails on labels

Postby jcompagner » Tue Sep 20, 2011 9:54 am

maria wrote:
True, but in designer we can use onAction on a label.


and on action is not onfocus so what are you trying to say?

maria wrote:See, my problem is this: we have multiple windows in our application and I keep track of each window's data environment. When changes happen to data I must know exactly in which window they are happening.
This is why I need to have a base method in the base form from which everything else is inheriting, that will always keep track of the active window. That is, when I'm changing the data in window 'A' and then click on a 'search' label, for example, in window 'B', I need a way of knowing it happened and switch the active window variable to the appropriate window. I did it in onRecordEditStart (before it came to labels) and it worked well until I found myself in a scenario where no data change happens on a label click but later in the code I need to have switched the active window to the one with that label and it didn't happen because onRecordEditStart hasn't fired and onElementFocusGained doesn't work on labels.

Perhaps it's a little complicated, but anyway, is there a chance that onElementFocusGained will be working on other elements than fields?
Otherwise, how do I determine the moment another window got focus?


Not everything will get focus. But i my eyes you are trying to do the wrong thing

If you want to have the real scope at the moment of some datachange, then you should just get the real scope at the moment of that data change, don't depend on focus stuff for that

Code: Select all
currentcontroller.getFormContext() //or controller.getFormContext()


will give you the complete context where the form is in.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: onElementFocusGained fails on labels

Postby maria » Thu Sep 22, 2011 8:37 am

jcarlos wrote:
maria wrote:See, my problem is this: we have multiple windows in our application and I keep track of each window's data environment. When changes happen to data I must know exactly in which window they are happening.


I am writing this from my iPhone so I have to be short.

If I were you, I used a global such as

var windowsenvironment = ""; 

I'd then use this to identify the base form (by the form name perhaps). The global could be set on show form property - maybe. 

Hope this help. Best, Carlos


This will not work, Carlos. The form is shown, then another window is shown and when the user goes back to the first form it will not run onShow again.
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: onElementFocusGained fails on labels

Postby maria » Thu Sep 22, 2011 8:56 am

jcompagner wrote:
maria wrote:
True, but in designer we can use onAction on a label.


and on action is not onfocus so what are you trying to say?

maria wrote:See, my problem is this: we have multiple windows in our application and I keep track of each window's data environment. When changes happen to data I must know exactly in which window they are happening.
This is why I need to have a base method in the base form from which everything else is inheriting, that will always keep track of the active window. That is, when I'm changing the data in window 'A' and then click on a 'search' label, for example, in window 'B', I need a way of knowing it happened and switch the active window variable to the appropriate window. I did it in onRecordEditStart (before it came to labels) and it worked well until I found myself in a scenario where no data change happens on a label click but later in the code I need to have switched the active window to the one with that label and it didn't happen because onRecordEditStart hasn't fired and onElementFocusGained doesn't work on labels.

Perhaps it's a little complicated, but anyway, is there a chance that onElementFocusGained will be working on other elements than fields?
Otherwise, how do I determine the moment another window got focus?


Not everything will get focus. But i my eyes you are trying to do the wrong thing

If you want to have the real scope at the moment of some datachange, then you should just get the real scope at the moment of that data change, don't depend on focus stuff for that

Code: Select all
currentcontroller.getFormContext() //or controller.getFormContext()


will give you the complete context where the form is in.


Um.. This actually makes sense.
And it works, thank you :D

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney


Return to Methods

Who is online

Users browsing this forum: No registered users and 6 guests