Created
March 19, 2011 06:17
-
-
Save thiamteck/877276 to your computer and use it in GitHub Desktop.
JQuery Datepicker with Month and Year only
This file contains 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
$(document).ready(function(){ | |
$(".monthPicker").datepicker({ | |
dateFormat: 'mm-yy', | |
changeMonth: true, | |
changeYear: true, | |
showButtonPanel: true, | |
onClose: function(dateText, inst) { | |
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val(); | |
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val(); | |
$(this).val($.datepicker.formatDate('yy-mm', new Date(year, month, 1))); | |
} | |
}); | |
$(".monthPicker").focus(function () { | |
$(".ui-datepicker-calendar").hide(); | |
$("#ui-datepicker-div").position({ | |
my: "center top", | |
at: "center bottom", | |
of: $(this) | |
}); | |
}); | |
}); |
This file contains 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
<label for="month">Month: </label> | |
<input type="text" id="month" name="month" class="monthPicker" /> |
This seems to have a bug. When you use older dates:
yearRange: "1900:2020",
minDate: "-80Y",
maxDate: "+2Y",
And then type the date in, it seems to default back to 2008 for me.
<3 thiamteck <3
thanks a loooot
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
inst
variable passed to theonClose()
function already has the month and year parsed out into it asselectedYear
andselectedMonth
, so you can do:rather than finding
month
andyear
from more jQuery DOM-diving.