-
18 Nov 2011 3:14 AM #1
Unanswered: Sending extra parameters when saving a model instance (on record.save())
Unanswered: Sending extra parameters when saving a model instance (on record.save())
Hi there.
I need to send some extra parameters to the server when updating/creating a record/model, but can't figure out how. Something like this:
Then when some imaginary button is clickedCode:// Show form etc.. var form = new Ext.form.Panel(); var record = new Model(); form.loadRecord(record); form.show();
I've searched the forums and api, but only way i've managed to do it is to add extra fields to my model, which I don't want, since its used elsewhere.Code:var record = form.getRecord(); record.set(form.getValues()); record.save({ extraParams : { // this is what i want to do, to send additional parameters param1 : 'some value', param2 : 'some other value' }, success : function(record) { // all good } })
-
18 Nov 2011 5:42 AM #2
-
18 Nov 2011 8:06 AM #3
in my case it will not work...
-
21 Nov 2011 12:31 AM #4
This kindof does the job, but the params are always added to the querystring even though request method is not GET.Code:record.save({params:{foo:'bar'}});
In my scenario i'm using a RESTful store, so it would be nice if params added could be sent in the same manner default params are (GET, POST, PUT, DELETE)
-
21 Nov 2011 1:29 AM #5
-
21 Nov 2011 11:40 AM #6
You could do that, even though i'm not so sure its a bug, but rather limitations of the current http-protocol - especially in terms of the DELETE request where its not safe to send a body with the request: (http://stackoverflow.com/questions/2...delete-request)
It would still be nice to hear what the developers has to say on the topic.
Essentially, what i need to do is to send some meta information when i update or delete a model instance. For example i want the end user to specify a reason for deleting. For now i've reverted to doing a form post and manually reloading the store at need. Kind of hackish. Thanks for your input though!
-
21 Nov 2011 10:57 PM #7
i overwrite writeRecords to have the functionality:
Code:writeRecords: function(request, data) { var root = this.root; Ext.applyIf(data[0], request.params || {}); if (this.allowSingle && data.length == 1) { // convert to single object format data = data[0]; } if (this.encode) { if (root) { // sending as a param, need to encode request.params[root] = Ext.encode(data); } else { //<debug> Ext.Error.raise('Must specify a root when using encode'); //</debug> } } else { // send as jsonData request.jsonData = request.jsonData || {}; if (root) { request.jsonData[root] = data; } else { request.jsonData = data; } } return request; }
-
23 Nov 2011 4:09 AM #8
I tested your override, but it still just gets appended to the querystring (as in GET).
-
23 Nov 2011 11:36 AM #9
Did you use extraParams or params? When using my override you must use it like:
Code:record.save({params:{foo:'bar'}});
-
30 Nov 2011 5:10 AM #10
I use params as specified, but its always appended to querystring regardless of http method


Reply With Quote