PDA

View Full Version : Ext.data.Model.isModified(...) always returns false



sschulze
18 Jul 2011, 7:21 AM
Hi,

I have an Store with AjaxProxy with attached update-listener, which is displayed by Ext.ux.TouchGridPanel. When I change one of the records, the update-event is successfully fired, but if I call record.isModified(...) for each of the models properties, it always returns false even though operation=='edit' and I got no operation=='commit' or 'rejected' and record.dirty==true.
To workaround this issue, I tried record.getChanges(), but this seems to be empty, too.
I didn't find the place where the modified-hash is populated, so can you guide me, how I bring Sencha Touch to populate this hash or how I can correctly query the modified property of the record?



Ext.regModel('Count',{
fields: [
{name:'id', type: 'integer'},
{name:'type', type: 'string'},
{name:'count', type: 'integer'}
]
});

countStore=new Ext.data.Store({
model: 'Count',
storeId: 'countStore',
proxy: {
type: 'ajax',
url: 'someUrl',
reader: {
idProperty: 'id',
root: 'counts'
}
},
listeners: {
update: function(store, record, operation){
if (operation==Ext.data.Model.EDIT){
var foo=record.getChanges();
if (record.isModified('count')){
// NEVER REACHING THIS POINT
alert('Changed count');
//Send to server
//onSuccess: record.commit()
}else{
record.commit();
}
}
}
}
});

sschulze
19 Jul 2011, 7:10 AM
Hi again,

I created a little minimal-example to demonstrate the issue:


Ext.regModel('TestModel',{
fields: [
{name:'value', type: 'integer'}
]
});

store=new Ext.data.Store({
model: 'TestModel',
data: [{value: 1}],
listeners: {
update: function(store, record, operation){
if (operation==Ext.data.Model.EDIT){
var dirty=record.dirty;
alert('Dirty: '+dirty+'\n'+'isModified: '+record.isModified('value')+'\n'+'Current value: '+record.get('value'));
record.commit();
}
}
}
});

new Ext.Application({
launch: function() {
rootPanel=new Ext.Panel({
fullscreen:true,
items: [{
xtype: 'button',
text: 'Change',
handler: function(){
var obj=store.getAt(0);
obj.set('value',obj.get('value')+1);
}
}]
});
this.viewport=rootPanel;
}
});

No foreign library is necessary besides Sencha Touch. If you execute the example, only a button is displayed. If you click the button, the only object in the store is modified by increasing the only property of the object. As expected, the update-event is fired, the object is marked as dirty, but - according to isModified(...) - the property is not modified.
Is this possibly a bug in Sencha Touch?

elesen
1 Sep 2011, 5:38 PM
Hi, the isModified('fieldName') works well in my app. (ExtJS4.0)