1. #1
    Sencha User
    Join Date
    Nov 2008
    Location
    Lyon, France
    Posts
    218
    Vote Rating
    5
    christophe.geiser will become famous soon enough

      0  

    Default [4.1] Uncaught TypeError with Ext.selection.Model

    [4.1] Uncaught TypeError with Ext.selection.Model


    Hi all
    this part of the code (Ext.selection.Model) creates an Uncaught TypeError: Cannot read property 'id' of undefined later in the execution.
    Code:
    doSelect: function(records, keepExisting, suppressEvent) {
            var me = this,
                record;
    
    
            if (me.locked || !me.store) {
                return;
            }
            if (typeof records === "number") {
                records = [me.store.getAt(records)];
               records = me.store.getAt(records); // this would be better, instead of above
            }
            if (me.selectionMode == "SINGLE" && records) {
                record = records.length ? records[0] : records;
                
    
                me.doSingleSelect(record, suppressEvent);
            } else {
                me.doMultiSelect(records, keepExisting, suppressEvent);
            }
        },
    It happens when 'records' is a number for which no records exist in the store. We should test the existence of record being passed to doSingleSelect and doMultiSelect :
    if(record) {me.doSingleSelect ...

    Cheers,
    C.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Vote Rating
    847
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    So you are trying to select something that doesn't exist?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Nov 2008
    Location
    Lyon, France
    Posts
    218
    Vote Rating
    5
    christophe.geiser will become famous soon enough

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    So you are trying to select something that doesn't exist?

    Well, I think the framework is trying to somehow ...


    This type of scenario occurs for instance when user tries to navigate though a boundlist for which the store is empty. At some point in Ext.selection.DataViewModel, we have :
    Code:
    onNavKey: function(step) {
    step = step || 1;
           var me = this,
               view = me.view,
               selected = me.getSelection()[0], // in this case, no selection
               numRecords = me.view.store.getCount(),
               idx;
    
    
    
    
           if (selected) {
               idx = view.indexOf(view.getNode(selected)) + step;
           } else {
               idx = 0;
           }
    
    
    
    
           if (idx < 0) {
               idx = numRecords - 1;
           } else if (idx >= numRecords) {
               idx = 0;
           }
           me.select(idx);// so idx = 0 at this point !
    }
    This leads to doSelect function above with records argument = 0, and hence the problem:
    Code:
    me.doSingleSelect(record, suppressEvent) // here record == undefined 
    The real problem in this case is that
    if (me.selectionMode == "SINGLE" && records)
    will always be true.


    Thanks for looking into this,
    C.

Thread Participants: 1