Search code examples
ajaxtwitter-bootstrapx-editable

X-Editable - Submit old value


Well I'm using the X-Editable and wanted to know if it's possible to submit the new value and the old one. For instance, the field has "Portugal". Using the X-Editable inline I change it to "Spain". In the AJAX Request I want to send the primary key, the old and the new value in order to validate if the value was changed by someone else when querying the database. Is this possible and I'm missing some part of the documentation or not?

Cheers.


Solution

  • For anyone having the same issue I found it in the documentation X-editable Docs that you can manually edit/append the values that will be submitted via AJAX to the server. So in my case, to obtain the original value I used this little code snippet:

    $('.editable').editable({
        params: function(params) {
            // Add originalValue to existing params
            params.originalValue = $(this).text();
    
            return params;
        }
    });
    

    With this, in the server I have access to the old and the new value and perform some validations with those. Hope this will help somebody.