From 44c24493b6f5dcea0ccc2332c136dd5807cafe03 Mon Sep 17 00:00:00 2001 From: Olivier PEREZ Date: Mon, 30 Nov 2015 22:23:57 +0100 Subject: [PATCH] Check date format and display warning on the failing fields --- js/app/date_poll.js | 47 ++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/js/app/date_poll.js b/js/app/date_poll.js index 659d3a8..861a4f4 100644 --- a/js/app/date_poll.js +++ b/js/app/date_poll.js @@ -52,6 +52,10 @@ $(document).ready(function () { var dtsplit = dateStr.split(/[\/ .:-]/); var dfsplit = format.split(/[\/ .:-]/); + if (dfsplit.length != dtsplit.length) { + return null; + } + // creates assoc array for date var df = []; for (var dc = 0; dc < dtsplit.length; dc++) { @@ -239,26 +243,37 @@ $(document).ready(function () { // console.log('start_date as date', startDate); // console.log('start_end as date', endDate); - if (startDate <= endDate) { - while (startDate <= endDate) { - var dateStr = formatDate(startDate, window.date_formats.DATE); - if (!useFirstEmptyDateField(dateStr)) { - newDateFields(dateStr); + if (startDate != null && endDate != null) { + if (startDate <= endDate) { + while (startDate <= endDate) { + var dateStr = formatDate(startDate, window.date_formats.DATE); + if (!useFirstEmptyDateField(dateStr)) { + newDateFields(dateStr); + } + startDate.setDate(startDate.getDate() + 1); } - startDate.setDate(startDate.getDate() + 1); + + // Hide modal + startDateField.val(''); + endDateField.val(''); + $('#add_days').modal('hide'); + submitDaysAvalaible(); + + } else { + setTimeout(function () { + startDateField.parent().addClass('has-error'); + endDateField.parent().addClass('has-error'); + }, 200); + } - - // Hide modal - startDateField.val(''); - endDateField.val(''); - $('#add_days').modal('hide'); - submitDaysAvalaible(); - } else { setTimeout(function () { - startDateField.parent().addClass('has-error'); - endDateField.parent().addClass('has-error'); - + if (startDate == null) { + startDateField.parent().addClass('has-error'); + } + if (endDate == null) { + endDateField.parent().addClass('has-error'); + } }, 200); }