goog.events.listen key-press event

<oXygen/> general issues.
john_m
Posts: 32

goog.events.listen key-press event

Fri Aug 04, 2017 9:24 pm

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: 123

Re: goog.events.listen key-press event

Tue Aug 08, 2017 4:59 pm

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

Return to “Other Issues”

Who is online

Users browsing this forum: No registered users and 1 guest