From a4e2b8043cbbea304e0c2b883d760098201e5cb7 Mon Sep 17 00:00:00 2001 From: Quincy Morgan <2046746+quincylvania@users.noreply.github.com> Date: Thu, 15 Oct 2020 16:48:45 -0400 Subject: [PATCH] Validate filter date values from hash/input Compensate if from date is set after to date --- modules/renderer/photos.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/modules/renderer/photos.js b/modules/renderer/photos.js index 4076a75b4..1c1d97569 100644 --- a/modules/renderer/photos.js +++ b/modules/renderer/photos.js @@ -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) {