In Place Edit With Callback

Blog Projects
javascript jeditable jquery
HEADS UP! This article was written in 2007. Information provided might not be valid anymore and should be taken with a grain of salt.

jQuery in place edit is now close to have all features it needs. Add some more and it will become feature creep. Most features are configurable. You can even get full control on Ajax request. Just write your own function for submitting and post to this function instead of URL. Smartypants!.

As usual, download latest source or test online.

Using callback function

Now you can define optional callback function. This function is called after form has been submitted. Callback function receives two parameters. Value contains submitted form content. Settings contain all plugin settings. Inside function this refers to the original element.

 $(".editable").editable("http://www.example.com/save.php", {
     type    : "textarea",
     submit  : "OK",
 }, function(value, settings) {
     console.log(this);
     console.log(value);
     console.log(settings);
 });

Submitting to function instead of URL

Parameters passed are now same as with callback. Example below does not do anything useful. It only demonstrates available parameters.

 $(".editable").editable(function(value, settings) {
     console.log(this);
     console.log(value);
     console.log(settings);
     return(value);
  }, {
     type    : "textarea",
     submit  : "OK",
 });

Note that function must return string. Usually the edited content. This will be displayed on page after editing is done.

Changelog

New features:

Added support for callbacks.
If target is function it will receive plugin settings as second parameter.

Bugs fixed:

Fix problems with IE when style is inherit.



When asking a question include an URL to example page where the problem occurs. Even better is to make a Fiddle which demonstrates the problem. If you have longer code examples please use pastie.org.
CATEGORIES
Built using the awesome Flat UI Pro framework by Designmodo.

Mika Tuupola is a Member of the Leanpub Affiliate Program.

© 2014 Mika Tuupola.