Results 1 to 2 of 2

Thread: BasicForm reset should remove reference to _record

    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
    26
      0  

    Default 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;
        },
    <div style="float: left; width: 70px;">http://appac.us/mcs.png</div><div style="float: left; height: 100px;">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</div><div style="clear:both;"></div>

  2. #2
    Sencha - Ext JS Dev Team dongryphon's Avatar
    Join Date
    Jul 2009
    Location
    Kansas
    Posts
    1,711
    Vote Rating
    240
      0  

    Default

    Thanks for the great bug report! Fixed for 4.1.2
    Don Griffin
    Director of Engineering - Frameworks (Ext JS / Sencha Touch)

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

    "Use the source, Luke!"

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
  •