PDA

View Full Version : Prevent post on insert as in rest proxy example



BenJenkin
22 Feb 2012, 8:03 PM
Hi,

In the rest proxy example clicking add does not automatically generate post event. Why is this? I would like to achieve the same but when I insert into the store it automatically posts.

Here is my code

ResourceFieldController.js

Ext.define('noclash.controller.ResourceFieldController', { extend: 'Ext.app.Controller',
stores: 'ResourceFields',
models: 'ResourceField',



refs : [
{ref: 'ResourceFieldsGrid', selector: 'ResourceFieldsGrid'}
],

init : function() {
console.log('initialized resourcefieldcontroller');
this.control({
'ResourceFieldsGrid button[action=add]' : {
click: this.addResourceField
}
});
},

addResourceField : function() {
console.log('add clicked');
grid = this.getResourceFieldsGrid();
var plugin=grid.getPlugin('fieldEditor');
store = this.getResourceFieldsStore();
store.insert(0, new this.getResourceFieldModel());
plugin.startEdit(0, 0);
}
});

ResourceFields.js

Ext.define('noclash.store.ResourceFields' , { extend: 'Ext.data.Store',
requires: 'noclash.model.ResourceField',
model: 'noclash.model.ResourceField',
autoLoad: true,
autoSync: true,


proxy: {
type: 'rest',



url: 'app/data/services.php',
extraParams: {
xsource: 'resourceInfoStore',
ResourceType: 1

},
reader: {
type: 'json',
root: 'results'
},
writer: {
type: 'json'
}
},
listeners: {
write: function(store, operation){
console.log('writing');

}
}

});

mitchellsimoens
23 Feb 2012, 7:39 AM
If you are talking about the writer.html example, the reason is because the new record isn't valid until you fill in the email, first name and last name. The model has validations and to send a record in a create sync call the record must be a phantom and be valid.

BenJenkin
24 Feb 2012, 12:02 AM
Ok great. How do I switch the question to answered?