What can I do to this piece of code to ensure that it can allow absences to be added in the past as well as the future? Whenever I attempt to add anything in the past, it is appears to want to still give me the error that I cannot add an absence in the past. I’m not even sure how to code to ensure it can, or which bit to delete. I’m aware there is a bit of code that is not allowing me to, but I’m not sure which bit and what to delete. I am not extremely skilled at JavaScript but it is in my project and I am unsure what to do with it.
dateValid: function () {
var s = $(this).val();
if ($(this).required()) {
var date = new Date(s);
if (!isNaN(date)) {
if (date >= Date.parse(new Date().toDateString())) {
$(this).removeClass("error");
return true;
}
else {
validation.showError("Past", $(this).attr("name"));
$(this).addClass("error");
return false;
}
}
else {
validation.showError("Invalid", $(this).attr("name"));
$(this).addClass("error");
return false;
}
}
else return false;
},
dateRangeValid: function (toDate) {
var s = $(this).val();
if ($(this).required()) {
if (toDate.required()) {
var dateFrom = new Date(s);
var dateTo = new Date(toDate.val());
if (!isNaN(dateFrom) && !isNaN(dateTo)) {
if (dateTo >= dateFrom) {
if (dateFrom >= Date.parse(new Date().toDateString())) {
$(this).removeClass("error");
toDate.removeClass("error");
return true;
}
else {
validation.showError("Past", "date");
$(this).addClass("error");
toDate.addClass("error");
return false;
}
}
else {
validation.showError("Invalid", "date");
$(this).addClass("error");
toDate.addClass("error");
return false;
}
}
else {
validation.showError("Invalid", "date");
$(this).addClass("error");
toDate.addClass("error");
return false;
}
}
else {
validation.showError("Required", "dateTo");
$(this).addClass("error");
toDate.addClass("error");
return false;
}
}
else {
validation.showError("Required", "dateFrom");
$(this).addClass("error");
toDate.addClass("error");
return false;
}
},
Here’s your error:
Replace with
and there should no longer be a problem.