webix.event without an ID

Hi,

I was recently trying to hook up key up and down event handlers for the document object. I really wanted to use webix.event(), but unfortunately, that doesn’t look to be possible. I was trying this:

webix.event(document, “onkeydown”, keyDownHandler);
webix.event(document, “onkeyup”, keyDownHandler);

It looks like that first argument MUST be an ID, which means this won’t work, based on looking at the event() code.

I think a really nice change in event() would be to do:

if (typeof node === “string”) {
node = webix.toNode(node);
}

That way, if the caller passes in a reference to a DOM node then you skip the lookup and attach the event, otherwise do the lookup and then the same assert logic as is done now. That would be really helpful I think (and really, I think anywhere in Webix where a DOM node is expected it should always accept a reference before doing any lookup logic).

Thanks,
Frank

looks like you are using typescript. try to cast document as any
webix.event(document as any, "keydown", handler)
or add custom definition

Nope, using Javascript.

  1. I don’t know what is your Webix version but in the source code of latest version, I saw that the first parameter can be string (ID of element) or HTML node.

webix.event=function(node,event,handler,context){

}

the node argument can be string (ID of HTML element) or HTML element.

  1. You code is wrong. You shouldn’t put “on” in your event name.
    It should be:
    webix.event(document, “keyup”, function() {
    webix.message(“keyup”);
    });

Tested with a snippet: https://webix.com/snippet/ba974067