Hi @Audreyma,
I just checked the code that we talked about previously on my trial portal and everything work as intended. See code below:
function dateCheck(){
let startDate = new Date($("#hero_startdate").val());
let endDate = new Date($("#hero_enddate").val());
if(startDate > endDate) {
alert("End date need to be bigger then start date");
}
}
$( document ).ready(function() {
console.log( "ready!" );
$("#hero_enddate").next().on("dp.change", function(ev) {
console.log("Dp change",ev);
dateCheck();
});
});
Regarding form validators: it is indeed useful when you want to prevent form submission and add additional validation. In the example, in the docs, it prevents submission and adds an error span with the message. It should look like this (with your fields):
$(document).ready(function () {
if (typeof (Page_Validators) == 'undefined') return;
// Create new validator
let newValidator = document.createElement('span');
newValidator.style.display = "none";
newValidator.id = "cr_enddayValidator";
newValidator.controltovalidate = "cr_endday";
newValidator.errormessage = "<a href='#cr_endday_label'>End date must be bigger then start date.</a>";
newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
newValidator.initialvalue = "";
newValidator.evaluationfunction = function () {
let startDate = new Date($("#hero_startdate").val());
let endDate = new Date($("#hero_enddate").val());
if (startDate > endDate) {
return false;
} else {
return true;
}
};
// Add the new validator to the page validators array:
Page_Validators.push(newValidator);
// Wire-up the click event handler of the validation summary link
$("a[href='#cr_endday_label']").on("click", function () {
scrollToAndFocus('cr_endday_label', 'cr_endday');
});
});
Can you also tell me how you add the code to the form?