function runFormEnhancer(){ if(addonSettings.allowResend!=false) $("#finishForm").attr("style","display:block !important"); checkDatePickersDateNotFuture(); } function checkDatePickersDateNotFuture() { var currentDate = new Date(); addonSettings.dateSettings.datePickersPreventFutureDatesFieldIDs.forEach(currentDatePicker => { $(`[fieldid='fld_${currentDatePicker}']`).blur(function() { let chosenParsedDate = Date.parse(this.value); let chosenDate=""; if(isNaN(chosenParsedDate)!=false) chosenDate = convertDateFormat(this.value); else chosenDate=this.value; if(Date.parse(chosenDate) > Date.parse(currentDate)){ alert(addonSettings.dateSettings.futureDateErrorMessage); this.value=getCurrentDate(); } }); }); } // Utils // This function returns the current date in the format used in israel function getCurrentDate(){ var newDate = new Date(); var currentDate = ""; if(newDate.getDate() <= 9) currentDate+= `0${newDate.getDate()}`; else currentDate+= `${newDate.getDate()}`; if(newDate.getMonth() + 1 <= 9) currentDate+= `/0${newDate.getMonth()+1}`; else currentDate+= `/${newDate.getMonth()+1}`; currentDate += "/"+newDate.getFullYear(); return currentDate; } // This function receives a date in israel format and return date in us format. function convertDateFormat(date){ let splittedDate = date.split("/"); return `${splittedDate[1]}/${splittedDate[0]}/${splittedDate[2]}`; }