goog.events.listen key-press event

Oxygen general issues.
john_m
Posts: 32
Joined: Mon Apr 10, 2017 8:56 pm

goog.events.listen key-press event

Post by john_m »

Hello,

I'm trying to stop the propagation of the key-press event for the delete key by using the code below in the framework.js file.

Code: Select all

goog.events.listen(goog.dom.getDocument(), goog.events.EventType.KEYDOWN, function(e) {
if(e.keyCode == goog.events.KeyCodes.DELETE){
//do stuff...
e.getBrowserEvent().preventDefault();
e.getBrowserEvent().stopPropagation();
}
});
The delete key fails to stop propagating. Am I listening at the correct eventSource as in goog.events.listen(eventSource, eventType, listener, [capturePhase, [handler]]); for this action?

Any thoughts would be appreciated.

Thanks!
John
cristi_talau
Posts: 496
Joined: Thu Sep 04, 2014 4:22 pm

Re: goog.events.listen key-press event

Post by cristi_talau »

Hello,

It works if you listen on the "capture" phase (note the last parameter - true):

Code: Select all


goog.events.listen(goog.dom.getDocument(), goog.events.EventType.KEYDOWN, function(e) {
if(e.keyCode == goog.events.KeyCodes.DELETE){
//do stuff...
e.getBrowserEvent().preventDefault();
e.getBrowserEvent().stopPropagation();
}
}, true);
Anyway, depending on your use-case (e.g. if you are trying to alter the behaviour of the editor deletion), using the Java API might be a better idea, for example https://www.oxygenxml.com/InstData/Edit ... ilter.html .

Best,
Cristian
Post Reply