mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Validate filter date values from hash/input
Compensate if from date is set after to date
This commit is contained in:
@@ -51,8 +51,25 @@ export function rendererPhotos(context) {
|
||||
};
|
||||
|
||||
photos.setDateFilter = function(type, val, updateUrl) {
|
||||
if (type === _dateFilters[0]) _fromDate = val;
|
||||
if (type === _dateFilters[1]) _toDate = val;
|
||||
// validate the date
|
||||
var date = val && new Date(val);
|
||||
if (date && !isNaN(date)) {
|
||||
val = date.toISOString().substr(0, 10);
|
||||
} else {
|
||||
val = null;
|
||||
}
|
||||
if (type === _dateFilters[0]) {
|
||||
_fromDate = val;
|
||||
if (_fromDate && _toDate && new Date(_toDate) < new Date(_fromDate)) {
|
||||
_toDate = _fromDate;
|
||||
}
|
||||
}
|
||||
if (type === _dateFilters[1]) {
|
||||
_toDate = val;
|
||||
if (_fromDate && _toDate && new Date(_toDate) < new Date(_fromDate)) {
|
||||
_fromDate = _toDate;
|
||||
}
|
||||
}
|
||||
dispatch.call('change', this);
|
||||
if (updateUrl) {
|
||||
setUrlFilterValue(type, val);
|
||||
@@ -118,7 +135,7 @@ export function rendererPhotos(context) {
|
||||
photos.toDate = function() {
|
||||
return _toDate;
|
||||
};
|
||||
|
||||
|
||||
photos.togglePhotoType = function(val) {
|
||||
var index = _shownPhotoTypes.indexOf(val);
|
||||
if (index !== -1) {
|
||||
|
||||
Reference in New Issue
Block a user