View Full Version : Is it possible to mark an Ext.data.Field as readonly?

7 Jan 2011, 11:32 AM
I have a JsonStore configured like this:

var store = new Ext.data.JsonStore({
// basic properties
restful: true,
autoSave: true,

// json writer
writer: new Ext.data.JsonWriter({
encode: false,
writeAllFields: true

// field config
fields: [
{ name: 'timestamp', type: 'date', dateFormat: 'c' }

The timestamp property should be set by the server, and the client should only read it. However, if I try to add or update a record using the JsonStore:

// add a record
var record = new store.recordType({ name: 'New record' });
store.insert(0, record);

// update a record
var record = store.getAt(0);
record.set('name', 'Modified record');

The JSON that's being sent over to the server looks like this:

"id": 5,
"name": "Modified record",
"timestamp": "01-06-2001T15:23:14"

I'd like it to stop sending over the timestamp property, since it's supposed to be read-only. Is there any way of configuring either the store or the record in order to get this behavior?

7 Jan 2011, 2:11 PM
Why do you need to write all the fields from the writer?

7 Jan 2011, 2:17 PM
Yeah, the writeAllFields property is telling the JsonWriter to send all the fields to the server. You could turn that off, or you could handle it on the server by simply ignoring that parameter instead of writing it to the database.


7 Jan 2011, 3:28 PM
I need the writeAllFields property to be true because the web service is configured to replace the database entity with the entity sent over by the client. If the client doesn't send over a property, the server will assume that property is null and will assign it that way.

I configured the server so that it will ignore the timestamp property, but optimally I'd like to not send it in the first place.

8 Jan 2011, 2:02 AM
You can remove the timestamp before it is sent, e.g.

writer: new Ext.data.JsonWriter({
encode: false,
writeAllFields: true,
toHash: function() {
var data = this.constructor.prototype.toHash.apply(this, arguments);
delete data.timestamp;
return data;