开发者

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

开发者 https://www.devze.com 2023-04-12 21:05 出处:网络
I have a grid bound to a form the forms submit action is t开发者_StackOverflow中文版o 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 a

I have a grid bound to a form the forms submit action is t开发者_StackOverflow中文版o 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?


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.


For anyone interested, you can override the default form panel to add functionality to clear form fields. Add the following to your code:

     Ext.override(Ext.form.Panel, {
         clearForm:function(){
             Ext.each(this.getForm().getFields().items, function(field){
                    field.setValue('');
             });
         }
    });

You can then clear a form using:

myForm.clearForm()

Where myForm is your form panel.


This is what you looking for:

form.getForm().reset(true);

True to unbind any record set by loadRecord.

See Ext.form.Basic.reset() syntax


I find this question because I have a similar scenario but slightly different:

  • ExtJS 4.1.1
  • TreePanel

In ExtJS 4.1 in sync() method you can use an options object in which you can define a callback, success and failure functions. Since I'm sure I'm only synchronozing just one record, I loaded the returned record:

me.getHelpItemsStore().sync({
    success: function(batch) {
        // We expect single operation so...
        var record = batch.operations[0].getRecords()[0];
        form.loadRecord(record);
    }
});

Little late but hope helps you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号