Search code examples
extjsextjs3

Uncaught TypeError: Cannot call method 'format' of undefined


I am using extjs version 3.4 and I am getting one error in this line:

var query = new RegExp(Ext.String.format('field1', e.query.replace(/\?/g, '[A-Za-z0-9]'))); 
like--Uncaught    TypeError: Cannot call method 'format' of undefined

I added listener like this please let me know if there is any wrong in this.

this.findById('field1').addListener({
    beforequery: function (e) {
        if (e.query && e.query.indexOf('?') != -1) {
            e.cancel = true;
            var query = new RegExp(Ext.String.format('field1', e.query.replace(/\?/g, '[A-Za-z0-9]')));
            this.expand();
            this.store.clearFilter(true);
            this.store.filter(this.displayField, query);
        }
    }
});

Solution

  • Just in case you were wondering why it is working with String instead of Ext.String it is because Ext is adding the method to the JavaScript String object.

    http://docs.sencha.com/ext-js/3-4/#!/api/String

    These functions are available as static methods on the JavaScript String object.

    So all of the other function for String that Ext defines (toggle, trim, etc.) will also be on String object and not Ext.String.

    Hope that helps for why it wasn't working and for the future.