Jeditable CANCEL callback from AJAX callback?
Asked Answered
B

1

7

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);
 }
Blossomblot answered 15/7, 2009 at 0:16 Comment(0)
M
5

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.

Masterson answered 27/7, 2009 at 18:17 Comment(1)
Thanks a lot, I tested and it's working like a charm, also the onedit callback, you see, the real problem was how could I hide a edit button on edit jeditable and show again on cancel/submit. Well is just call a $('#div').hide(); or .show() inside of this callbacks.Blossomblot

© 2022 - 2024 — McMap. All rights reserved.