Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extjs 4 form still has record set after form.reset();

Tags:

extjs

I have a grid bound to a form the forms submit action is to update the loaded record if there is one and add a new record if its a blank form. but if I select a record first and then call

myGrid.getSelectionModel().deselectAll();
myform.getForm().reset(); 

to clear the form so I can add a new record it overwrites the previously selected record with an update.

record = myform.getRecord();
if(record){
record.set(values);
}

shouldn't myform.getRecord(); be null after a reset? how do I clear the record selection?

like image 417
Early73 Avatar asked Oct 13 '11 02:10

Early73


1 Answers

In short, no, it shouldn't and you don't have legal approaches to clear the record after the first time you load anything via loadRecord.
Although, you could still do myform.getForm()._record = null assignment, I would strongly object against that, as it may break some internal functionality by ExtJS.

Here is an extract from ExtJS API:

getRecord() : Ext.data.Model
Returns the last Ext.data.Model instance that was loaded via loadRecord

And it does exactly that, returns the last record loaded via loadRecord.

Here are some sources:

getRecord: function() {
    return this._record;
},

loadRecord: function(record) {
    this._record = record;
    return this.setValues(record.data);
},

Actually, those are the only methods of Ext.form.Basic (an instance of which is returned by getForm()) dealing with this._record field.

As for reset

reset: function() {
    var me = this;
    me.batchLayouts(function() {
        me.getFields().each(function(f) {
            f.reset();
        });
    });
    return me;
},

As you could see, reset has nothing to do with the record returned by getRecord(), it's just resetting field values.

like image 61
Li0liQ Avatar answered Nov 09 '22 19:11

Li0liQ