Extjs 4 form still has an entry after form.reset ();

I have a grid attached to the form that represents the action of the form, to update the loaded record, if there is one, and add a new record if its form is empty. but if you select the record first and then call

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

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

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

should not myform.getRecord (); be null after a reset? how to clear record selection?

+5
source share
4 answers

, , , , - loadRecord.
myform.getForm()._record = null, , ExtJS.

ExtJS API:

getRecord(): Ext.data.Model
Ext.data.Model loadRecord

, , loadRecord.

:

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

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

, Ext.form.Basic ( getForm()) this._record.

reset

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

, reset , getRecord(), .

+3

, , , , . :

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

, :

myForm.clearForm()

myForm - .

+2

, :

form.getForm().reset(true);

, loadRecord.

. Ext.form.Basic.reset()

+2

, , :

  • ExtJS 4.1.1
  • TreePanel

In ExtJS 4.1, in the sync () method, you can use the options object in which you can define callback, success, and failure functions. Since I am sure that I only sync only one record, I downloaded the returned record:

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

A little late, but hope will help you.

0
source

All Articles