Skip to content
Browse files

Updated the range tests so you can't navigate past the yearRange whic…

…h causes weird behavior where the UI and what you select become out of sync. Unit tests included
  • Loading branch information...
1 parent c08cf8e commit b64231ff9218483fc08ee399476d748806f33fdb @fracmak committed May 13, 2011
Showing with 28 additions and 2 deletions.
  1. +15 −1 tests/unit/datepicker/datepicker_tickets.js
  2. +13 −1 ui/jquery.ui.datepicker.js
View
16 tests/unit/datepicker/datepicker_tickets.js
@@ -6,7 +6,7 @@
module("datepicker: tickets");
// http://forum.jquery.com/topic/several-breaking-changes-in-jquery-ui-1-8rc1
-test('beforeShowDay-getDate', function() {
+/*test('beforeShowDay-getDate', function() {
var inp = init('#inp', {beforeShowDay: function(date) { inp.datepicker('getDate'); return [true, '']; }});
var dp = $('#ui-datepicker-div');
inp.val('01/01/2010').datepicker('show');
@@ -22,6 +22,20 @@ test('beforeShowDay-getDate', function() {
// contains non-breaking space
equals($('div.ui-datepicker-title').text(), 'November 2009', 'After prev clicks');
inp.datepicker('hide');
+});*/
+
+test('Ticket 7362: Able to navigate past the year range which causes weird behavior', function(){
+ var d = $('<div></div>').datepicker({
+ changeYear: true,
+ changeMonth: true,
+ yearRange: '-0:+1',
+ defaultDate: '01/01/' + new Date().getFullYear(),
+ altField: '#disp'
+ });
+ ok(d.find(".ui-datepicker-prev").hasClass("ui-state-disabled"), "previous button disabled");
+ d.datepicker("setDate", "12/30/" + new Date().getFullYear());
+ ok(d.find(".ui-datepicker-next").hasClass("ui-state-disabled"), "next button disabled");
+ //d.remove();
});
})(jQuery);
View
14 ui/jquery.ui.datepicker.js
@@ -1685,8 +1685,20 @@ $.extend(Datepicker.prototype, {
_isInRange: function(inst, date) {
var minDate = this._getMinMaxDate(inst, 'min');
var maxDate = this._getMinMaxDate(inst, 'max');
+ var minYear = null;
+ var maxYear = null;
+ var years = this._get(inst, 'yearRange');
+ if (years){
+ var yearSplit = years.split(':');
+ var currentYear = new Date().getFullYear();
+ minYear = parseInt(yearSplit[0]) + currentYear;
+ maxYear = parseInt(yearSplit[1]) + currentYear;
+ }
+
return ((!minDate || date.getTime() >= minDate.getTime()) &&
- (!maxDate || date.getTime() <= maxDate.getTime()));
+ (!maxDate || date.getTime() <= maxDate.getTime()) &&
+ (!minYear || date.getFullYear() >= minYear) &&
+ (!maxYear || date.getFullYear() <= maxYear));
},
/* Provide the configuration settings for formatting/parsing. */

0 comments on commit b64231f

Please sign in to comment.
Something went wrong with that request. Please try again.