Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

datepicker-restricted-fix: datepicker had a bug in restricted logic that... #650

Merged
merged 1 commit into from
Sep 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified dist/fuelux.zip
Binary file not shown.
5 changes: 4 additions & 1 deletion dist/js/fuelux.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,10 @@
for ( i = 0, l = restricted.length; i < l; i++ ) {
from = restricted[ i ].from;
to = restricted[ i ].to;
if ( ( date >= from.date && month >= from.month && year >= from.year ) && ( date <= to.date && month <= to.month && year <= to.year ) ) {
if (
( year > from.year || ( year === from.year && month > from.month ) || ( year === from.year && month === from.month && date >= from.date ) ) &&
( year < to.year || ( year === to.year && month < to.month ) || ( year === to.year && month === to.month && date <= to.date ) )
) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/js/fuelux.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion js/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@
for(i=0,l=restricted.length; i<l; i++){
from = restricted[i].from;
to = restricted[i].to;
if((date>=from.date && month>=from.month && year>=from.year) && (date<=to.date && month<=to.month && year<=to.year)){
if(
(year>from.year || (year===from.year && month>from.month) || (year===from.year && month===from.month && date>=from.date)) &&
(year<to.year || (year===to.year && month<to.month) || (year===to.year && month===to.month && date<=to.date))
){
return true;
}
}
Expand Down
13 changes: 8 additions & 5 deletions test/datepicker-moment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,19 @@ define(function(require){
test('should restrict days if restricted option is set', function(){
var $datepicker = $(html).datepicker({
allowPastDates: true,
date: new Date(1987, 3, 5),
restricted: [{ from: new Date(1987, 3, 1), to: new Date(1987, 3, 4) }, { from: new Date(1987, 3, 13), to: new Date(1987, 3, 17) }]
date: new Date(1987, 2, 5),
restricted: [{ from: new Date(1987, 2, 1), to: new Date(1987, 2, 4) }, { from: new Date(1987, 2, 28), to: new Date(1987, 3, 1) }]
});
var dates = ['1', '2', '3', '4', '13', '14', '15', '16', '17'];
var dates = ['1', '2', '3', '4', '28', '29', '30', '31', '1'];
var i=0;
var self = this;
var month = '2';

$datepicker.find('.restricted').each(function(){
var $item = $(this);
equal(($item.attr('data-date')===dates[i] && $item.attr('data-month')==='3' && $item.attr('data-year')==='1987'), true,
if(i>7) {
month = '3';
}
equal(($item.attr('data-date')===dates[i] && $item.attr('data-month')===month && $item.attr('data-year')==='1987'), true,
'correct date restricted as expected');
i++;
});
Expand Down
15 changes: 9 additions & 6 deletions test/datepicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,20 @@ define(function(require){
test('should restrict days if restricted option is set', function(){
var $datepicker = $(html).datepicker({
allowPastDates: true,
date: new Date(1987, 3, 5),
restricted: [{ from: new Date(1987, 3, 1), to: new Date(1987, 3, 4) }, { from: new Date(1987, 3, 13), to: new Date(1987, 3, 17) }]
date: new Date(1987, 2, 5),
restricted: [{ from: new Date(1987, 2, 1), to: new Date(1987, 2, 4) }, { from: new Date(1987, 2, 28), to: new Date(1987, 3, 1) }]
});
var dates = ['1', '2', '3', '4', '13', '14', '15', '16', '17'];
var dates = ['1', '2', '3', '4', '28', '29', '30', '31', '1'];
var i=0;
var self = this;
var month = '2';

$datepicker.find('.restricted').each(function(){
var $item = $(this);
equal(($item.attr('data-date')===dates[i] && $item.attr('data-month')==='3' && $item.attr('data-year')==='1987'), true,
'correct date restricted as expected');
if(i>7) {
month = '3';
}
equal(($item.attr('data-date')===dates[i] && $item.attr('data-month')===month && $item.attr('data-year')==='1987'), true,
'correct date restricted as expected');
i++;
});

Expand Down