this.setSize is not a function

Posted on Jan 09, 2009 under xn--zqqs84h3is.com | edit
  • Hi, all
    I just did an upgrade from Ext2.0 beta1 to the most recent release Ext2.0.2 downloaded from the Extjs.com download area, then all the code related to my toolbar with buttons are broken, I got error message "this.setSize is not a function", after I commented out the tbar or bbar section, then it is fine. for example:

    grid = new Ext.grid.GridPanel({
    id:'msggrid',
    region:'center',
    layout:'fit',
    border:false,
    ds: new Ext.data.Store({
    reader: new Ext.data.ArrayReader({}, myRecordObj)
    }),
    cm: cm,
    sm: new Ext.grid.RowSelectionModel({selectRow:Ext.emptyFn} ),
    shadow: false,
    shadowOffset: 0,
    tbar: [
    new Ext.Button({
    id: 'addmorebtn',
    tooltip: 'Add more',
    handler: function() {
    Ext.Msg.alert('Click', 'add');
    }
    }) ],
    viewConfig: {
    forceFit:true,
    enableRowBody:true,
    showPreview:true,
    getRowClass : function(record, rowIndex, p, store){
    if(this.showPreview){
    p.body = '

    '+record.data.message+'

    ';
    return 'x-grid3-row-expanded';
    }
    return 'x-grid3-row-collapsed';
    }
    }
    });

    Not sure what has changed in the new release which has impact, it happened in afterrender() with addButton() call in ext-all-debug.js, I searched the forum, so far no entry about this error.

    Anybody happens to know what I need to change to display buttons on toolbar?

    Thanks

    Dave


  • Something's weird then.

    Because you should be able to add ordinary Buttons to a Toolbar, but not to a Window or Panel unless they implement BoxComponent. That's why I didn't suggest using my BoxButton extension.


  • Animal, thanks for your response, after some debugging, I found the problem is that Ext.Button is not extended from BoxComponent, which has size, after I changed the code to:
    var addmorebtn = new Ext.ux.form.BoxButton({
    id: 'addmorebtn',
    tooltip: 'Add',
    iconCls: 'user-add',
    handler: function() {
    Ext.Msg.alert('Click', 'add');
    }
    });

    Then the problem is sovled, this problem only applies to buttons on toolbar, if I add a Ext.Button on items or buttons to Ext.Window or a Panel, then it is fine.

    Since this problem happened to all the buttons on a toolbar, even the buttons on my htmlEditor toolbar, not sure what the best way is to fix it, since I am using HtmlEditor and it is defined in the ext library, I have to rewrite the code to change all the toolbar buttons to use Ext.ux.form.BoxButton instead of Ext.Button.

    Any ideas about what happened to the 2.0.2 new release in terms of the buttons on toolbar and the best way to fix it?

    Thanks

    Dave


  • Break on the error, trace back through the call stack, see who's calling setSize on something that doesn't have it.


  • Ok, I got it clearer now, two things I need to do to fix this:
    1. To add a button to a toolbar, I need to instantiate a Ext.Toolbar.Button instead of Ext.Button:
    var addmorebtn = new Ext.Toolbar.Button({
    id: 'addmorebtn',
    tooltip: 'Add',
    iconCls: 'user-add',
    handler: function() {
    Ext.Msg.alert('Click', 'add');
    }
    });

    2. I can not use this code:

    Ext.ux.BoxButton = Ext.extend(Ext.BoxComponent, Ext.apply({
    constructor: Ext.Button
    }, Ext.Button.prototype)
    );
    Ext.reg('boxbutton', Ext.ux.BoxButton);

    Ext.override(Ext.BoxComponent, {
    adjustSize : function(w, h){
    if(this.autoWidth === true){
    w = 'auto';
    }
    if(this.autoHeight === true){
    h = 'auto';
    }
    return {width : w, height: h};
    }
    });

    Not sure why, otherwise my toolbar buttons will always call Ext.Button instead of Ext.Toolbar.Button unless I explicitly use xtype: 'boxbutton' or instantiate Ext.ux.BoxButton and add it to toolbar.

    Thanks

    Dave







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about this.setSize is not a function , Please add it free.