Mika has done a fantastic job supplying the jQuery community with his excellent in-place editing add-in jEditable.
He has also graciously provided us with a page explaining how to add custom input types.
But for us jEditable noobs looking to add custom input types to our pages…there was nowhere to go to find out how to tie it all together…that’s what this post will hopefully do.
Since we almost always keep our javascript in a separate file, let’s start with the html…
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<script src="/scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="/scripts/jquery-ui-1.8.1.custom.min.js" type="text/javascript"></script>
<script src="/scripts/jquery.jeditable.js" type="text/javascript"></script>
<script src="/scripts/demo.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
You’ll notice that we’ve added four javascript files…jQuery itself…jQuery UI (be sure and select the Datepicker widget when building your jQuery UI download)…the jEditable file and our custom demo file.
Now we’ll just add in some css files and a table…
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<link href="/content/Site.css" rel="stylesheet" type="text/css" />
<link href="/content/ui-lightness/jquery-ui-1.8.1.custom.css" rel="stylesheet" />
<script src="/scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="/scripts/jquery-ui-1.8.1.custom.min.js" type="text/javascript"></script>
<script src="/scripts/jquery.jeditable.js" type="text/javascript"></script>
<script src="/scripts/demo.js" type="text/javascript"></script>
</head>
<body>
<div align="center">
<table class="checkbookChecksTable centerMyTable">
<thead></thead>
<tbody>
<tr>
<td style="width: 70px;">
<span class="">A Batch ID1</span>
</td>
<td style="width: 70px;">
<span class="">2010-01-27</span>
</td>
<td style="width: 70px;">
2010-01-20
</td>
<td style="width: 90px;">
An Account Code1
</td>
<td style="width: 90px;">
An Account Code1 Description
</td>
<td style="width: 90px;">
A Vendor 1
</td>
<td style="width: 70px;">
($114.56)
</td>
<td style="width: 50px;">
<input type="button" class="checkbookButton" value="Save">
</td>
</tr>
<tr>
<td style="width: 70px;">
<span class="">A Batch ID2</span>
</td>
<td style="width: 70px;">
<span class="">2010-01-01</span>
</td>
<td style="width: 70px;">
2010-01-01
</td>
<td style="width: 90px;">
An Account Code2
</td>
<td style="width: 90px;">
An Account Code 2 Description
</td>
<td style="width: 90px;">
A Vendor 2
</td>
<td style="width: 70px;">
($55.67)
</td>
<td style="width: 50px;">
<input type="button" class="checkbookButton" value="Save">
</td>
</tr>
<tr>
<td style="width: 70px;">
<span class="">A Batch ID2</span>
</td>
<td style="width: 70px;">
<span class="">2010-01-01</span>
</td>
<td style="width: 70px;">
2010-01-01
</td>
<td style="width: 90px;">
An Account Code3
</td>
<td style="width: 90px;">
An Account Code 3 Description
</td>
<td style="width: 90px;">
A Vendor 3
</td>
<td style="width: 70px;">
$1,252.90
</td>
<td style="width: 50px;">
<input type="button" class="checkbookButton" value="Save">
</td>
</tr>
</tbody>
<tfoot></tfoot>
</table>
</div>
</body>
</html>
OK, so now our page looks like this…just a simple table for illustration purposes…

A simple table
Let’s build our demo.js file now…
$(document).ready(function() {
$('.editabledatepicker').editable(function(value, settings) {
return (value);
}, {
type: 'datepicker',
onblur: 'submit',
tooltip: "Click to edit...."
});
});
See the selector referencing the class editabledatepicker…that’s just normal jEditable syntax right?…so let’s go ahead and add that class to the appropriate cells in our table…
Here’s what one of the rows looks like now with the editabledatepicker class added…
<tr>
<td style="width: 70px;">
<span class="">A Batch ID1</span>
</td>
<td style="width: 70px;">
<span class="editabledatepicker">2010-01-27</span>
</td>
<td style="width: 70px;">
2010-01-20
</td>
<td style="width: 90px;">
An Account Code1
</td>
<td style="width: 90px;">
An Account Code1 Description
</td>
<td style="width: 90px;">
A Vendor 1
</td>
<td style="width: 70px;">
($114.56)
</td>
<td style="width: 50px;">
<input type="button" class="checkbookButton" value="Save">
</td>
</tr>
Here’s where the real magic comes into play…notice in our first run at our javascript file, we specified a type when setting up our editabledatepicker
type: 'datepicker',
so now we have to let jEditable know about our datepicker type with this little bit of javascript…
jQuery.editable.addInputType('datepicker', {
element: function(settings, original) {
var input = jQuery('<input size=8 />');
// Catch the blur event on month change
settings.onblur = function(e) {
};
input.datepicker({
dateFormat: 'yy-mm-dd',
onSelect: function(dateText, inst) {
// you may want to remove this or
// change it to
// jQuery(this).submit();
// see GamB's comments below
jQuery(this).parents("form").submit();
},
onClose: function(dateText, inst) {
// you may want to change this to
// jQuery(this).submit();
// see GamB's comments below
jQuery(this).parents("form").submit();
}
});
input.datepicker('option', 'showAnim', 'slide');
jQuery(this).append(input);
return (input);
}
});
…see the addInputType?
That’s how we add a custom input type to jEditable!
Now our js file looks like this…
$(document).ready(function() {
jQuery.editable.addInputType('datepicker', {
element: function(settings, original) {
var input = jQuery('<input size=8 />');
// Catch the blur event on month change
settings.onblur = function(e) {
};
input.datepicker({
dateFormat: 'yy-mm-dd',
onSelect: function(dateText, inst) {
jQuery(this).parents("form").submit();
},
onClose: function(dateText, inst) {
jQuery(this).parents("form").submit();
}
});
input.datepicker('option', 'showAnim', 'slide');
jQuery(this).append(input);
return (input);
}
});
$('.editabledatepicker').editable(function(value, settings) {
return (value);
}, {
type: 'datepicker',
onblur: 'submit',
tooltip: "Click to edit...."
});
});
and…when we click in the date cell…we’ll see this…

the calendar
When we choose a date, it’s written back to the table cell…works just as we’d expect!