Buy Now
Sign in

Validate a calendar field with a custom javascript code

tchaabid , February 02 at 08:09
T
tchaabid

Hello. I'm trying to perform a verification for my calendar field but my javascript code don't work. I want my field to display an error message when the user put a date greater than today's one.

jQuery.fn.form.settings.rules.verifdatecreation = function(value, param) {

var currentDate = new Date().setHours(0,0,0,0);
var selectedDate = new Date(value);

if (selectedDate > currentDate) {
return false;
}else{
return true;
}
};
admin
Hi tchaabid,
You do not need to validate this, open the calendar advanced settings and set the "End date" to:
{date:Y-m-d}
This will restrict the date selection to end on the same day.
Best regards
Max
If your main question got answered then please mark the answer using the button!​

Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!