Results 1 to 10 of 10

Thread: Form loadRecord issue when model contains field 'length'

    You found a bug! We've classified it as EXTJS-5106 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Sencha User
    Join Date
    Jan 2011
    Posts
    1
    Vote Rating
    0
      0  

    Exclamation Form loadRecord issue when model contains field 'length'

    When loading a record on a form it ends up verifying if it's an object or an array, If the record contains the field 'length' it will return true and the loadRecord method will not work accordingly but without failing.

    isIterable: function(value) {
    return (value && typeof value !== 'string') ? value.length !== undefined : false;
    }



  2. #2
    Touch Premium Member
    Join Date
    Jan 2011
    Posts
    5
    Vote Rating
    0
      0  

    Default Demo of that problem

    Just adding a working demo that shows the problem.

    http://jsfiddle.net/rgilbert1021/RbKPJ/1/

  3. #3
    Sencha Premium Member
    Join Date
    Mar 2010
    Posts
    15
    Vote Rating
    0
      0  

    Default I am having the same problem!!!

    Anybody cares to look into this?!

  4. #4
    Sencha Premium Member
    Join Date
    Mar 2010
    Posts
    15
    Vote Rating
    0
      0  

    Default Form loadRecord issue when model contains field 'length'

    REQUIRED INFORMATIONExt version tested:
    • Ext 4.0.7
    Browser versions tested against:
    • FF9 (firebug 1.3.0.10 installed)
    • Safari 4
    Description:When loading a record on a form it ends up verifying if it's an object or an array, If the record contains the field 'length' it will return true and the loadRecord method will not work accordingly but without failing.
    Code:
    isIterable: function(value) {
    return (value && typeof value !== 'string') ? value.length !== undefined : false;
    }
    

    Steps to reproduce the problem:
    See demo: http://jsfiddle.net/rgilbert1021/RbKPJ/1/
    The result that was expected:
    The field name should be able to be 'length'
    Test Case:
    http://jsfiddle.net/rgilbert1021/RbKPJ/1/
    HELPFUL INFORMATION
    See this URL for live test case:
    http://http://jsfiddle.net/rgilbert1021/RbKPJ/1/
    Possible fix:
    Code:
            isIterable: function(value) {
                return value && Ext.isArray(value);
            }

  5. #5
    Sencha User hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966
    Vote Rating
    15
      0  

    Default

    @allunsun --
    Thanks for the report [again] !

    Ext 4.1B1 is also susceptible to this problem.

    Here is a more complete implementation for Ext.isIterable until this is patched:
    Code:
    Ext.isIterable = function(value){
               
           var type = typeof value, 
                 checkLength = value instanceof Array;     
    
            if (value && type == "function") {             
                   checkLength = value instanceof NodeList || value instanceof HTMLCollection;
            }  
            return checkLength ? 'length' in value : false; 
      };
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  6. #6
    Sencha Premium Member
    Join Date
    Jan 2008
    Posts
    115
    Vote Rating
    28
      0  

    Default Trying to implement patch

    Thanks for the workaround, but who do I use it?

    Tried just copying it into my regular JS file, didn't work. Tried to use an override, didn't work either. Now I am getting other JS errors. Where would I put this code to make it work?

    Code:
    Ext.define("ExtPatched", {
        override: "Ext",
        isIterable: function(value){
            
            var type = typeof value, 
                  checkLength = value instanceof Array;     
    
             if (value && type == "function") {             
                    checkLength = value instanceof NodeList || value instanceof HTMLCollection;
             }  
             return checkLength ? 'length' in value : false; 
       }
    });

  7. #7
    Sencha Premium Member
    Join Date
    Mar 2010
    Posts
    15
    Vote Rating
    0
      0  

    Default

    I got the following patch working correctly for 4.1
    Code:
    Ext.override(Ext, {    isIterable : function(value) {
            var type = typeof value, checkLength = false;
            if (Ext.isObject(value)) {
                return false;
            }
            if (value && type != 'string') {
                // Functions have a length property, so we need to filter them out
                if (type == 'function') {
                    // In Safari, NodeList/HTMLCollection both return "function" when using typeof, so we need
                    // to explicitly check them here.
                    if (Ext.isSafari) {
                        checkLength = value instanceof NodeList || value instanceof HTMLCollection;
                    }
                } else {
                    checkLength = true;
                }
            }
            return checkLength ? length !== undefined : false;
        }
    });

  8. #8
    Sencha Premium Member
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    53
    Vote Rating
    3
      0  

    Default Fix confirmed for ExtJs 4.2.0

    @allansun Thanks. This fix is still needed () and working for ExtJS 4.2.0 (release) too!

  9. #9
    Sencha Premium Member
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    53
    Vote Rating
    3
      0  

    Default One more fix...

    ... is needed to make sure Ext.data.reader.Reader can read te records properly in ExtJs 4.2.0

    Code:
     
        Ext.override(Ext.data.reader.Reader, {
                extractData: function (root) {
                    var me = this,
                        Model   = me.model,
                        length  = root.length,
                        records = new Array(length),
                        convertedValues, node, record, i;
    
                    if (!Ext.isArray(root)) {
                        root = [root];
                        length = 1;
                    }
    
                    for (i = 0; i < length; i++) {
                        node = root[i];
                        if (node.isModel) {
                            // If we're given a model instance in the data, just push it on
                            // without doing any conversion
                            records[i] = node;
                        } else {
                            // Create a record with an empty data object.
                            // Populate that data object by extracting and converting field values from raw data.
                            // Must pass the ID to use because we pass no data for the constructor to pluck an ID from
                            records[i] = record = new Model(undefined, me.getId(node), node, convertedValues = {});
    
                            // If the server did not include an id in the response data, the Model constructor will mark the record as phantom.
                            // We  need to set phantom to false here because records created from a server response using a reader by definition are not phantom records.
                            record.phantom = false;
    
                            // Use generated function to extract all fields at once
                            me.convertRecordData(convertedValues, node, record);
    
                            if (me.implicitIncludes && record.associations.length) {
                                me.readAssociated(record, node);
                            }
                        }
                    }
    
                    return records;
                }
            });

  10. #10
    Sencha Premium Member
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    53
    Vote Rating
    3
      0  

    Default

    This issue was _NOT_ fixed in 4.2.2

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •