Created
May 15, 2011 20:41
-
-
Save Jaskirat/973512 to your computer and use it in GitHub Desktop.
jeditable datepicker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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