Search code examples
javascriptextjsextjs4

What is the proper way to unload/unbind a record from a form in ExtJS 4?


I want to allow users to create new records and edit existing records from the same form in ExtJS 4. I am working with ExtJS 4.0.7.

It's easy for me to load a record.

var form = Ext.ComponentQuery.query('#myForm');
form.loadRecord(record);

But if I want to start fresh, there is no way to unload it! At least, no proper way that I can find. I've already researched for hours, and even looked through some of the core Ext code for an answer. The best I could come up with to "unload" a record is:

form._record = null;

If I don't explicitly declare _record as null, Ext will always try to update the record stored there. form.reset(); does not clear the loaded record either.

Is there a "proper" way to clear the record tied to a form so that a new record can be saved?


Solution

  • Ext.form.Panel is derived from Ext.form.Basic, where _record exists as a private variable. And if you take a look into the code of Ext.form.Basic http://docs.sencha.com/ext-js/4-0/source/Basic.html#Ext-form-Basic-method-getRecord you'll note that there is no clear method for _record. reset method just do reset of form fields. So you're doing right when setting form._record = null; Personally, I'd prefer to do delete form._record, but your approach should work either.