Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-6595 in a recent build.
  1. #1
    Sencha User grgur's Avatar
    Join Date
    Aug 2007
    Location
    Split, Croatia
    Posts
    155
    Vote Rating
    24
    grgur has a spectacular aura about grgur has a spectacular aura about

      0  

    Default BasicForm reset should remove reference to _record

    BasicForm reset should remove reference to _record


    Ext version tested:
    • Ext 4.1

    Browser versions tested against:
    • Chrome 21

    DOCTYPE tested against:
    • <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

    Description:
    • I am using the same instance of a form to create and update data in a store. When I update, i use loadRecord() to load data from an existing Ext.data.Model instance. If the next step was creating a record, just by doing formPanel.getForm().reset() will still keep the old _record reference in memory, thus updateRecord() will try to write over the last record used. reset method should ideally delete the _record reference, and updateMethod should exit gracefully if no record is supplied.
    • Not sure if this is a feature request or a bug. The whole idea is lessening the amount of code on the app side and keeping the logic within the framework

    Possible fix:
    Code:
        // Ext.form.Basic
       reset: function() {
            Ext.suspendLayouts();
    
            var me     = this,
                fields = me.getFields().items,
                f,
                fLen   = fields.length;
    
            for (f = 0; f < fLen; f++) {
                fields[f].reset();
            }
    
            // delete reference to me._record if it exists
            delete me._record;
    
            Ext.resumeLayouts(true);
            return me;
        },
        
        updateRecord: function(record) {
            record = record || this._record;
            
            // just exit gracefully if record does not exist
            if (!record) {
                return false;
            }
            var fields = record.fields.items,
                values = this.getFieldValues(),
                obj = {},
                i = 0,
                len = fields.length,
                name;
    
            for (; i < len; ++i) {
                name  = fields[i].name;
    
                if (values.hasOwnProperty(name)) {
                    obj[name] = values[name];
                }
            }
    
            record.beginEdit();
            record.set(obj);
            record.endEdit();
    
            return this;
        },
    Grgur Grisogono
    Ext JS in Action SE co-author
    Exercising awesomeness at Modus Create - Official Sencha Partner

    Get in touch for Sencha Touch Training
    @ggrgur

  2. #2
    Sencha - Ext JS Dev Team dongryphon's Avatar
    Join Date
    Jul 2009
    Posts
    1,382
    Vote Rating
    136
    dongryphon is a splendid one to behold dongryphon is a splendid one to behold dongryphon is a splendid one to behold dongryphon is a splendid one to behold dongryphon is a splendid one to behold dongryphon is a splendid one to behold

      0  

    Default


    Thanks for the great bug report! Fixed for 4.1.2
    Don Griffin
    Ext JS Development Team Lead

    Check the docs. Learn how to (properly) report a framework issue and a Sencha Cmd issue

    "Use the source, Luke!"

Thread Participants: 1

Tags for this Thread