Question
· Jun 14, 2018

AddEventListener for a control

Is there a way to add event listener for a zen control?

I have a custom text control and I want to add 'change' event listener for it.

Is it possible to do not using 'onchange' property? 

Discussion (3)0
Log in or sign up to continue

Try so:

Class dc.test Extends %ZEN.Component.page
{

XData Contents [ XMLNamespace "http://www.intersystems.com/zen" ]
{
  <page xmlns="http://www.intersystems.com/zen">
    <button id="btn1" caption="Test Server"/>
    <button id="btn2" caption="Test Client"/>
  </page>
}

ClassMethod SrvTest() [ ZenMethod ]
{
  &js<zenAlert('from Server');>
}

ClientMethod test() [ Language = javascript ]
{
  zenAlert('from Client');
}

ClientMethod onloadHandler() [ Language = javascript ]
{
  document.getElementById('btn1').addEventListener('click',new Function('evt','return zenPage.SrvTest();'),false);
  document.getElementById('btn2').addEventListener('click',new Function('evt','return zenPage.test();'),false);
}
}

This solution works for me.

Maybe somebody will  need it.

Method onloadHandler()  is  in custom text control class.


ClientMethod onloadHandler() [ Language = javascript ]
{

var comp this;
var elem this.findElement('control');

elem.addEventListener('click', function(){
        comp.someMethod();
    });
    
}