Created
August 22, 2013 16:24
-
-
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.
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
$(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