Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jeditable CANCEL callback from AJAX callback?

I see some answers for the Jeditable plugin to use a callback function from AJAX using complete callback function.

I know that the Jeditable has a callback function for the SUBMIT button, so I would like to know if there is a way to have a callback for the CANCEL button? I haven't found on the plugin docs.

Thanks for reply,

Carlos

PD. This is the source I see for COMPLETE from AJAX callback:

$("#editable_text").editable(submitEdit, { 
            indicator : "Saving...",
            tooltip   : "Click to edit...",
            name : "Editable.FieldName",
            id   : "elementid",
            type : "text",
});
function submitEdit(value, settings)
{ 
   var edits = new Object();
   var origvalue = this.revert;
   var textbox = this;
   var result = value;
   edits[settings.name] = [value];
   var returned = $.ajax({
           url: "http://URLTOPOSTTO", 
           type: "POST",
           data : edits,
           dataType : "json",
           complete : function (xhr, textStatus) 
           {
               var response =  $.secureEvalJSON(xhr.responseText);
               if (response.Message != "") 
               {
                   alert(Message);
               } 
           }
           });
   return(result);
 }
like image 572
Carlitux Avatar asked Jul 15 '09 00:07

Carlitux


1 Answers

Yes, there is a "onreset" parameter that is called when clicking cancel, or more generally, before jEditable resets the control back to the state before it was clicked. Add this to your code:

$("#editable_text").editable(submitEdit, { 
    //...
    onreset: jeditableReset,
    //...
});

function jeditableReset(settings, original) {
   // whatever you need to do here
}

This is documented in the header of the jquery.jeditable.js file.

Another note - if you don't submit on blur (you don't appear to be in the sample), the onreset event will fire then too.

like image 64
James Kolpack Avatar answered Oct 18 '22 10:10

James Kolpack