Defect #583

With showFormPopup keyListener doesn't work

Added by Andrej Candek about 5 years ago. Updated about 5 years ago.

Status:In Progress Start date:11/21/2012
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:-
Browser (if web client):
Votes: 0

Description

When i show the form with the

plugins.window.showFormPopup()

and in my onLoad method i put:

plugins.keyListeners.addKeyListener(elements.searchFilter, forms.myForm.onKeyPressed, 'keyPressed')

it doesn't work.

History

Updated by Patrick Talbot about 5 years ago

I'd say there's little chance that will ever work: showFormPopup() treats the form in the window as some kind of 'on-the-fly' tabPanel, adding listeners to it on the fly will most likely interfere with the events that Servoy is already trapping. Even if that worked, I would advise not to do that.

Updated by Patrick Talbot about 5 years ago

  • Status changed from New to In Progress

You're doing nothing wrong (except that you forgot to call plugins.keyListeners.removeAllKeyListeners() onUnload()), but the problem is that the component listeners never receives the event in case of a TAB.

My guess is that Servoy has other listeners (that would be dangerous to remove), that are trapping the events before they reach the plugin's own listeners and in case of TAB are consuming the event, so it never reaches the component.
This is because Servoy is handling the TAB key to move to the next field in the tab order index.
When the last field is reached though, this is the form which is handling the tab so the event reaches the component before it reaches the form in that case.

So in short, there is no way to trap the TAB key and prevent it. You can listen to it using the onElementFocusLost as you've done, but actually returning false doesn't prevent the focus to move to the next field.

Now the question is: what would you need to prevent the standard behavior of the TAB key, which is to go to the next field. Users are expecting that. Personally I would hate an app that would prevent me to use that behavior as I'm used to.

If you need some validation to occur when a field lose focus, you should try to build that validation in the onDataChange event and not mess with the standard behavior, really.

In any case, I'm afraid I cannot do a thing at the plugin level to trap events that the plugin doesn't receive in the first place...

Updated by Andrej Candek about 5 years ago

Thank you so much for your answer.

Is there any possibility to check if the textField has got a keyListener associated?

Updated by Patrick Talbot about 5 years ago

You mean one that you would have set yourself?
I suppose you can keep track of them (and you should, really, because you need to dispose of them to allow garbage collection: as long as a field has a listener on it, it will not be garbage collectable, nor will the form that holds him, so this could lead to memory leaks and eat up your memory in the end).
If you mean listeners that Servoy would have set on its own, there are various levels where that could happen so this would not be reliable.

Updated by Patrick Talbot about 5 years ago

  • Priority changed from High to Normal

Also available in: Atom PDF