Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 848
John Krull Avatar asked Nov 03 '11 19:11

John Krull


2 Answers

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.

like image 162
Pavel Podlipensky Avatar answered Nov 18 '22 06:11

Pavel Podlipensky


The docs describe that the reset method's optional first parameter to true unbinds any record set by loadRecord. So in Ext 4 and 5 you can just do:

yourForm.reset(true);

Internally it does:

delete me._record;
like image 2
Christiaan Westerbeek Avatar answered Nov 18 '22 07:11

Christiaan Westerbeek