1. #1
    Sencha User
    Join Date
    Mar 2007
    Posts
    34
    Vote Rating
    0
    grEvenX is on a distinguished road

      0  

    Default Bug in Button widget for 0.33 release

    Bug in Button widget for 0.33 release


    Thanks for a really great library.
    I've hade a bit of struggle keeping a good structure in my JavaScript code when using the library, but I think that's mostly the case of me being unfamiliar with too muck JavaScript coding...

    When using the Button widget (YAHOO.ext.Button) without assigning a handler, and instead using the addListener method, the javascript debugger complains about a javascript error:
    "this.handler has no properties"

    I guess there's something in the code that doesn't check wether an handler is set or not...

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    4
    tryanDLS is on a distinguished road

      0  

    Default


    Are you adding a handler to a valid event? (e.g. click not onclick). Do you have a scoping issue - is 'this' what you think it is?

    Can you post a code sample?

  3. #3
    Sencha User
    Join Date
    Mar 2007
    Posts
    34
    Vote Rating
    0
    grEvenX is on a distinguished road

      0  

    Default


    I think this sample code should be sufficient...

    HTML:
    Code:
    <div id="myTestButton"></div>
    Javascript code:
    Code:
    yuiBtn = new YAHOO.ext.Button('myTestButton', {text: "Next"});
    yuiBtn.on('click', myOnClickFunction);
    
    var myOnClickFunction = function(btn, evtObject) {
        alert("test");
    }

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    4
    tryanDLS is on a distinguished road

      0  

    Default


    Not sure if that code is all in one method, but you might try

    yuiBtn.on('click', this.myOnClickFunction)

    You might also want to pass the 3rd,4th args above (....yuiBtn, true)

    If you stop in the debugger in the click event, you'll probably see that 'this' is the window, not your method, so this.handler doesn't point to anything. You'll also see whether doing it your way with 2 args is sufficient to get the right values passed as btn, evtObject to your method.

  5. #5
    Sencha User
    Join Date
    Mar 2007
    Posts
    34
    Vote Rating
    0
    grEvenX is on a distinguished road

      0  

    Default


    Just wanted to note that replacing:
    Code:
    yuiBtn.on('click', myOnClickFunction);
    with the following line gets rid of the message:
    Code:
    yuiBtn.handler = {
    call: myOnClickFunction
    };

  6. #6
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    The problem was two fold. One, a bug in the lib when handler is null (it used to only support handler, so it was assuming it would be there). The updated version is in SVN, or you can include this somewhere after yui-ext:

    Code:
    YAHOO.ext.Button.prototype.onClick : function(e){
            e.preventDefault();
            if(!this.disabled){
                this.fireEvent('click', this, e);
                if(this.handler){
                    this.handler.call(this.scope || this, this, e);
                }
            }
        }
    The second problem is you are passing your function reference before the function is defined:

    yuiBtn = new YAHOO.ext.Button('myTestButton', {text: "Next"});
    yuiBtn.on('click', myOnClickFunction); <-- myOnClickFunction = undefined

    var myOnClickFunction = function(btn, evtObject) {
    alert("test");
    }

Similar Threads

  1. widget contest?
    By Draven in forum Ext 2.x: Help & Discussion
    Replies: 8
    Last Post: 30 Mar 2007, 10:22 AM
  2. Widget initial values
    By DrZog in forum Ext 1.x: Help & Discussion
    Replies: 6
    Last Post: 30 Mar 2007, 2:52 AM
  3. Toggle button: change button icon when pressed?
    By dbadke in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 26 Mar 2007, 7:14 AM
  4. Grid widget, PNG images & IE
    By BernardChhun in forum Ext 1.x: Help & Discussion
    Replies: 0
    Last Post: 13 Feb 2007, 5:44 AM
  5. The new release is out
    By jack.slocum in forum Community Discussion
    Replies: 2
    Last Post: 27 Sep 2006, 4:20 AM

Thread Participants: 2