Custom component event not fired

Hi

I want to create an element with specific handling of the keyboard, based on webix.ui.text, so I do this:

webix.protoUI({
name: “priceinput”,
on: {
‘onKeyPress’: function(code, ctrl, shift, event) {
console.log(code);
}
}
}, webix.ui.text);

  • now I can use a view type of ‘priceinput’ in my form, it works. But the keypress-event of the ‘priceinput’ is not fired.

Why not?

Using webix 2.5.8

Hi,

“on” handlers should be set when you initialize the view, not in view definition:

webix.ui({
   view: "priceinput",
    on: { 'onKeyPress': function(...) { ... } } },
   ....
}); 

If you want to set event handler for all priceinput views, you can set it in $init method:

webix.protoUI({ 
   name: "priceinput"
   $init: function(){
          this.attachEvent('onKeyPress',function(code, ctrl, shift, event) {
              console.log(code); 
          });
    }
},webix.ui.text);

or, you can place the “on” sections in defaults of a new view

http://webix.com/snippet/65b44812

Thank you, both, for the precise replys. Helped me a lot!

-mads