1. #1
    Ext JS Premium Member Spenna's Avatar
    Join Date
    Apr 2008
    Posts
    63
    Answers
    2
    Vote Rating
    0
    Spenna is on a distinguished road

      0  

    Default 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:
    Code:
    // Show form etc.. 
    var form = new Ext.form.Panel();
    var record = new Model();
    form.loadRecord(record);
    form.show();
    Then when some imaginary button is clicked
    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
        }
    })
    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.

  2. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,669
    Answers
    130
    Vote Rating
    110
    tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all

      0  

    Default


    edit: just took a look at the sources. try out

    Code:
    record.save({params:{foo:'bar'}});
    Best regards
    Tobias Uhlig
    __________

    S-CIRCLES Social Network Engine

  3. #3
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    670
    Answers
    6
    Vote Rating
    0
    Dumbledore is on a distinguished road

      0  

    Default


    in my case it will not work...

  4. #4
    Ext JS Premium Member Spenna's Avatar
    Join Date
    Apr 2008
    Posts
    63
    Answers
    2
    Vote Rating
    0
    Spenna is on a distinguished road

      0  

    Default


    Code:
    record.save({params:{foo:'bar'}});
    This kindof does the job, but the params are always added to the querystring even though request method is not GET.
    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)

  5. #5
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,669
    Answers
    130
    Vote Rating
    110
    tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all

      0  

    Default


    if you like to, i can move the topic to the bugreport forums.
    Best regards
    Tobias Uhlig
    __________

    S-CIRCLES Social Network Engine

  6. #6
    Ext JS Premium Member Spenna's Avatar
    Join Date
    Apr 2008
    Posts
    63
    Answers
    2
    Vote Rating
    0
    Spenna is on a distinguished road

      0  

    Default


    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!

  7. #7
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    670
    Answers
    6
    Vote Rating
    0
    Dumbledore is on a distinguished road

      0  

    Default


    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;
                }

  8. #8
    Ext JS Premium Member Spenna's Avatar
    Join Date
    Apr 2008
    Posts
    63
    Answers
    2
    Vote Rating
    0
    Spenna is on a distinguished road

      0  

    Default


    I tested your override, but it still just gets appended to the querystring (as in GET).

  9. #9
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    670
    Answers
    6
    Vote Rating
    0
    Dumbledore is on a distinguished road

      0  

    Default


    Did you use extraParams or params? When using my override you must use it like:


    Code:
    record.save({params:{foo:'bar'}});

  10. #10
    Ext JS Premium Member Spenna's Avatar
    Join Date
    Apr 2008
    Posts
    63
    Answers
    2
    Vote Rating
    0
    Spenna is on a distinguished road

      0  

    Default


    I use params as specified, but its always appended to querystring regardless of http method

Thread Participants: 2

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi