PDA

View Full Version : Delete empty entity from storage



mmuruev
12 Sep 2012, 12:52 AM
I use example code for ext 4 and grid edit throught form window but form request empty entity in storage for create new member and now problem with it while user change his mind and just close create form in this case I have empty entity in my storage how i can delete it only in this case? Create code
xtype:'toolbar', items:[
{
text:'Add',
iconCls:'icon-add',
handler:function () {
// empty record
store.insert(0, new Apache_config());
//rowEditing.startEdit(0, 0);
windowFormHandler(store.getAt(0));
}
},
I have trying just delete this in

Ext.create('Ext.window.Window', { .... renderTo:Ext.getBody(),
listeners:{
beforeclose:function (panel) {
// check any logical conditions here, then
// return true to allow the window to close
// or false to keep it open.
store.remove(store.getAt(0));
return true;
}
},


In this case it remove each time id=0 in store that obvious. How I can get in this handler that it was generated by Add button? And how add bind between form validation and form button( for dissabling Apply button if form not valid?).
I have that code

dirtychange::function (record) { this.activeRecord = record;
if (record) {
this.down('#save').enable();
this.getForm().loadRecord(record);
} else {
this.down('#save').disable();
this.getForm().reset();
}
},


But this even have no record as parameter.

mitchellsimoens
17 Sep 2012, 8:52 AM
store.getAt(0)

doesn't guarantee to get an item where id = 0, it gets the record at 0 index.

mmuruev
17 Sep 2012, 10:45 AM
Isn't index and id the same? But this code correct I've took it from official samples. It remove exactly just added storage object. Problem is how to distinct object created by Edit action or by Add action.

mitchellsimoens
17 Sep 2012, 11:12 AM
Isn't index and id the same?

No. You could have id 123456789 but have an index of 3