Page 1 of 1

goog.events.listen key-press event

Posted: Fri Aug 04, 2017 9:24 pm
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

Re: goog.events.listen key-press event

Posted: Tue Aug 08, 2017 4:59 pm
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