Skip to content

Commit 8ac1c88

Browse files
authored
Merge pull request #1142 from palak-here/fix/date-validation-1137
fix: validate invalid custom date inputs in date range filter
2 parents ea35ae2 + b71f8d4 commit 8ac1c88

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎script.js‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ function injectDateFilterBar() {
392392
' <label>To</label>',
393393
' <input type="date" id="gh-date-end" style="border:1px solid ' + borderColor + ';background:' + bgColor + ';color:' + textColor + '" />',
394394
' </div>',
395+
' <div id="gh-date-error" style="display:none;color:#ef4444;font-size:12px;width:100%;margin-top:4px;"></div>',
395396
' <button class="xf-apply" id="gh-date-apply">Apply</button>',
396397
'</div>',
397398
].join('\n');
@@ -443,7 +444,19 @@ function injectDateFilterBar() {
443444
document.getElementById('gh-date-apply').addEventListener('click', function() {
444445
var startVal = document.getElementById('gh-date-start').value;
445446
var endVal = document.getElementById('gh-date-end').value;
446-
447+
448+
var startInput = document.getElementById('gh-date-start');
449+
var endInput = document.getElementById('gh-date-end');
450+
var errorMsg = document.getElementById('gh-date-error');
451+
452+
errorMsg.style.display = 'none';
453+
454+
if (startInput.matches(":invalid") || endInput.matches(":invalid")) {
455+
errorMsg.textContent = "Please enter a valid calendar date.";
456+
errorMsg.style.display = "block";
457+
return;
458+
}
459+
447460
if (!startVal && !endVal) {
448461
ghDateFilter = { start: null, end: null };
449462
updateFilterBadge(null, null);
@@ -518,7 +531,7 @@ function filterReposByDate(repos) {
518531
return true;
519532
});
520533
}
521-
534+
522535
/** Re-render dashboard cards using cached data + current filter */
523536
function applyDateFilterAndRender() {
524537
if (!lastFetchedEvents && !lastFetchedRepos) return;

0 commit comments

Comments
 (0)