1. #1
    Ext User
    Join Date
    Mar 2007
    Location
    T
    Posts
    39
    Vote Rating
    0
    hicker is on a distinguished road

      0  

    Default appending an event listener

    appending an event listener


    hi, i want to create an input and handle some events of that input but couldn't make it. could somebody help about the code below. i get no error messages but it doesn't work.
    Code:
    var handleFocus = function(e){
    	alert('ok');
    };
    var parentElement = getEl('div1');
    var element = YAHOO.ext.DomHelper.append(parentElement, {tag:'input', type:'text', size:'15'}, true);
    element.mon('focus',handleFocus,this,true);

  2. #2
    Ext Premium Member BernardChhun's Avatar
    Join Date
    Mar 2007
    Location
    Quebec, Canada
    Posts
    831
    Vote Rating
    2
    BernardChhun will become famous soon enough

      0  

    Default Re: appending an event listener

    Re: appending an event listener


    Quote Originally Posted by hicker
    hi, i want to create an input and handle some events of that input but couldn't make it. could somebody help about the code below. i get no error messages but it doesn't work.
    Code:
    var handleFocus = function(e){
    	alert('ok');
    };
    var parentElement = getEl('div1');
    var element = YAHOO.ext.DomHelper.append(parentElement, {tag:'input', type:'text', size:'15'}, true);
    element.mon('focus',handleFocus,this,true);
    I must say I've never used the .mon() function before...but this works for me perfectly:
    Code:
    element.addListener('focus', function(){alert('ok')});

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Location
    Austin, Texas
    Posts
    4
    Vote Rating
    0
    brian.moeskau is an unknown quantity at this point

      0  

    Default


    hicker,

    The problem is that DomHelper.append expects a DOM node, not an Ext.Element, as the parent parameter. Change the param to parentElement.dom:

    Code:
    var handleFocus = function(e){
       alert('ok');
    };
    var parentElement = getEl('div1');
    var element = YAHOO.ext.DomHelper.append(parentElement.dom, {tag:'input', type:'text', size:'15'}, true);
    element.mon('focus',handleFocus,this,true);
    Alternatively (and more simply) you can simply pass in the parent ID and DomHelper will take care of the element lookup for you internally:

    Code:
    var handleFocus = function(e){
       alert('ok');
    };
    var element = YAHOO.ext.DomHelper.append('div1', {tag:'input', type:'text', size:'15'}, true);
    element.mon('focus',handleFocus,this,true);
    And you may already know if you've been following the Alpha discussions, getEl() and Element.mon() are being deprecated in 1.0 (in favor of Ext.get() and Element.on() -- which will return an Ext event object by default -- respectively).

    The changes to the event API in particular are worth noting more closely:
    http://www.yui-ext.com/forum/viewtopic.php?t=2520

    HTH,
    Brian

Similar Threads

  1. MessageBox TAB listener possible?
    By mikegiddens in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 7 Mar 2007, 1:25 PM
  2. Add Key Listener of 127/DEL
    By aconran in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 22 Feb 2007, 12:50 PM
  3. Delayed Listener Bug
    By n01champion in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 21 Feb 2007, 12:15 PM
  4. Borderlayout resize listener?
    By kjordan in forum Ext 1.x: Help & Discussion
    Replies: 7
    Last Post: 22 Dec 2006, 1:23 PM
  5. loadScripts using eval instead of appending to dom
    By jbowman in forum Community Discussion
    Replies: 1
    Last Post: 17 Nov 2006, 8:42 PM

Thread Participants: 2