Skip to content

Instantly share code, notes, and snippets.

@Jaskirat
Created May 15, 2011 20:41
Show Gist options
  • Save Jaskirat/973512 to your computer and use it in GitHub Desktop.
Save Jaskirat/973512 to your computer and use it in GitHub Desktop.
jeditable datepicker
$.editable.addInputType( 'datepicker', {
/* create input element */
element: function( settings, original ) {
var form = $( this ),
input = $( '<input />' );
input.attr( 'autocomplete','off' );
form.append( input );
form.append('<input id=jedate_ type=hidden value=false>')
return input;
},
/* attach jquery.ui.datepicker to the input element */
plugin: function( settings, original ) {
var form = this,
input = form.find( "input" );
// Don't cancel inline editing onblur to allow clicking
//datepicker
settings.onblur = 'nothing';
datepicker = {
onSelect: function() {
// clicking specific day in the calendar should
// submit the form and close the input field
form.submit();
//set the hidden field so that we know this closing is due
//selction and not due to clicking outside the calendar area
$('#jedate_').val('true');
},
onClose: function(dateText, instance) {
//reset form if selection was not done via calendar
//if enter key was used to save data, form will still be reset
if ($('#jedate_').val() == "false") {
original.reset( form);
}
}
};
if (settings.datepicker) {
jQuery.extend(datepicker, settings.datepicker);
}
input.datepicker(datepicker);
},
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment