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?
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With