views:

807

answers:

1

Hello,

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);
 }
+2  A: 

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.

James Kolpack
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.
Carlitux