Hi Brian,

How did you get on with adding checkbox support to jeditable, it would
be nice to have jeditable support all input types such as checkboxes
and radio buttons (the ok/cancel would need to be for the entire named
group) and of course password, and file. jeditable is pretty great as
it stands, but with a more rounded support it makes things that little
bit quicker.


I've yet to test this comprehensively, but I've written a very quick
proof of concept to allow the callback function make changes to the
value returned. This allows your callback function to intercept the
response from the server and process any validation messages you might
want to alert the user to.

On the simplest level:

 var callback = settings.callback || function() { };
becomes
 var callback = settings.callback || function(value, settings)
{ return value; };

callback.apply(self, [self.innerHTML, settings]);
becomes
$(self).html(callback.apply(self, [self.innerHTML, settings]));

This allows you to then use a callback to provide validation
responses, such as "edit unsaved, 'value' already exists" and then
return the control to it's original value or as desired...

As a quick example your server response might be "%%original value%%
[edit unsaved, '%%new value%%' already exists]" for a failure and "%
%new value%%" for a success together with a callback like the
following:

callback :function(value, settings) {
                  if(value.indexOf('[')>=0){
                                
alert(value.substring(value.indexOf('[')+1,value.indexOf(']')));
                                return value.substring(0,value.indexOf('['));
                }else{
                        return value;
                }
     }

of course you can put your validation message into an element on the
page rather than alert the message... Hopefully this illustrates the
power of a proper callback function and will see the idea develop
within the plugin.

Paul

Reply via email to