PDA

View Full Version : record.save() callback function



lilianfelismino
30 Nov 2011, 9:19 AM
Hello everyone!

I'm using record.save() to update a record. I had specified a callback on the options object, however, it is only called when the server returns a response with a FORBBIDEN status. I can't figure it out why it never calls the callback function when the server returns a response with an OK status. (I'm using sencha touch with phonegap and jersey restful webserver).

Thank you!

mitchellsimoens
30 Nov 2011, 11:34 AM
I think I remember earlier this year working on a project for a client where I had to patch Model in order to have it call the callback.

lilianfelismino
30 Nov 2011, 11:47 AM
What do you mean by "patch Model"? What did you actually do? (Sorry, english is not my native language.) I'm stucked with this problem for a week!

Thank you.

mitchellsimoens
30 Nov 2011, 12:06 PM
I had to override parts of the Model class. I don't remember exactly what I had to do.

lilianfelismino
1 Dec 2011, 4:04 AM
Ok... Thank you! Is there a possibility of such code to be on your GitHub page? :)

Thanks!

lilianfelismino
1 Dec 2011, 12:43 PM
Problem solved! Actually, the problem was when converting data! On our model, there is a field type "date" and the value returned by restful server was a "string". Therefore, we needed to change the convert function. Follows:

BEFORE:


{
name: 'birthDate',
type: 'date',
convert: function (value, record) {
var splits = value.split(" "),
date = new Date(split[0],replace(/-/g, "/"));
return date;
}
}


During process of saving, the value of the field was already a date object. That was the problem that crashed my code and wasn't calling the callback function. So we had to modify the convert function to verify if the value was already a date type.

AFTER:


{
name: 'birthDate',
type: 'date',
convert: function (value, record) {
var splits, date;
if (Ext.isDate(value)) {
date = value;
} else {
splits = value.split(" ");
date = new Date(splits[0].replace(/-/g, "/"));
}
return date;
}
}


Thanks!