Skip to content

Instantly share code, notes, and snippets.

@sycobuny
Created August 22, 2013 16:24
Show Gist options
  • Save sycobuny/6309501 to your computer and use it in GitHub Desktop.
Save sycobuny/6309501 to your computer and use it in GitHub Desktop.
Trying to get a jQuery-UI datepicker with a "clear" button on it is surprisingly difficult.
$(function() {
var datePickerCloseEventBound = false, currentDateInput
enableClearDatePickerButton = function(dateInput) {
currentDateInput = dateInput
if (datePickerCloseEventBound) return;
// sadly. the .ui-datepicker-close button doesn't exist yet :(
$('.ui-datepicker-close').click(function() {
$(currentDateInput).val('')
})
datePickerCloseEventBound = true
}
$('.datepicker').datepicker({
showAnim: 'blind',
showOn: 'button',
buttonImageOnly: true,
showButtonPanel: true,
closeText: 'Clear',
beforeShow: enableClearDatePickerButton
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment