View Full Version : When to add record to the store

7 Jul 2010, 3:59 PM
I am trying to understand when I should use the "add" method of the store to insert a new record into it. I have a RESTful store with autoSave = true, and I want to create a new record, databind it to a form, and when the user fills the form and presses "Save", I want a new record to be created (by a POST RESTful request).

Well, I found out that if I use "add" or "insert" to put the new record into the store, the POST request is sent immediately. So, does that mean that I should add the record to the store only when the user presses the Save button on the form? But, in case there is some validation error on the server, and the user corrects the error and presses Save again, I don't want to add the record to the store again, I guess.

Anyway, this is the code I tried, following some example:

Defining the form:

Application.EventsForm = Ext.extend(Ext.form.FormPanel, {
(... etc ....)
onUpdate : function(btn, ev) {
if (this.record == null) {
if (!this.getForm().isValid()) {
App.setAlert(false, "Form is invalid.");
return false;
this.getForm().updateRecord(this.record); // this will update the record in the store and cause a POST request
console.log('after updateRecord');

During initialization:

Ext.onReady(function() {

var events_form = new Application.EventsForm({
renderTo: 'events_form',

var events_store = Ext.StoreMgr.lookup('events_store');
var defaultData = {
name: 'Full Name',
start_dt: '',
end_dt: '',
timezone: '',
participants_count: '',
updated_on: ''
var r = new events_store.recordType(defaultData);
events_store.add(r); // this will cause an undesired POST request

What would be a good practice to accomplish this?