简体   繁体   中英

Send previous xeditable value to the server

I am using https://vitalets.github.io/x-editable/docs.html as a select element. In addition to sending the new value to the server (ie s, p), I would like to also send the previous value (ie b). The following script will do so initially, but will only send the original value (ie p) even if it is changed multiple times and the new previous value is no longer p.

<a href="javascript:void(0)" class="doc-type" data-value="b"></a>

$('.doc-type').editable({
    type: 'select',
    placement: 'right',
    title: 'Document Type',
    source: [{value:'b',text:'Buy'},{value:'s',text:'Sell'},{value:'p',text:'Project'}],
    //params: {task:'saveDocType',controller:'portal',cid:ayb.component.id,CSRF:ayb.CSRF,doc_id:function(){console.log(this);}},
    params: function(params) {
        //originally params contain pk, name and value
        delete(params.name);
        params.task = 'saveDocType';
        params.controller = 'portal';
        params.cid = ayb.component.id;
        params.CSRF = ayb.CSRF;
        params.doc_id=$(this).parent().parent().data('id');
        params.v_old=$(this).data('value');
        return params;
    },
    url: 'index.php',
    pk: function(){return $('#id').val();},
    error: function (response, newValue) {
        //Unlike other validation, save function to return non 200 header.
        return response.responseText;
    },
});

I expect there is a better way, but one option is to save the newValue in the success callback.

$('.doc-type').editable({
    type: 'select',
    source: [{value:'b',text:'Buy'},{value:'s',text:'Sell'},{value:'p',text:'Project'}],
    params: function(params) {
        //originally params contain pk, name and value
        params.v_old=$(this).data('value');
        return params;
    },
    url: 'index.php',
    pk: function(){return $('#id').val();},
    success: function(response, newValue) {
        $(this).data('value',newValue)
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM