How do I command the calendar function to have a warning message when a user chooses a date in the past (mm-dd-YYYY)?

Please download the premade validation script from here. After unzipping the file you can install it with the Breezingforms package installer and choose the script from the validation library as usual. Please make sure that the format in your calendar looks like this:

%m-%d-%Y 

Besides this you can use the following code directly as custom validation script in your element:

 

function ff_CALENDARITEMNAME_validation(element, message)
{
     if(element.value.split("-").length != 3){return message == '' ? element.name+" faild in my test.n" : message}

     var vDate = new Date(Number( element.value.split("-")[2]),Number(element.value.split("-")[0]-1),Number(element.value.split("-")[1]),0,0,0).getTime();


     var today = new Date();

     today.setHours(0);
     today.setMinutes(0);
     today.setSeconds(0);
     today.setMilliseconds(0);
     today = today.getTime();

     if(vDate < today)
     {
          if (message=='') message = element.name+" faild in my test.n";
          return message;
     }
     return '';
}

 

This example is for the js calendar date pattern (MM-DD-YYYY), therefore the javascript above might be slightly different for other patterns, for instance if you want another seperator. Assuming you need a " / " instead of a " - " the code would look like this:

 

function ff_CALENDARITEMNAME_validation(element, message)
{
     if(element.value.split("/").length != 3){return message == '' ? element.name+" faild in my test.n" : message}

     var vDate = new Date(Number( element.value.split("/")[2]),Number(element.value.split("/")[0]-1),Number(element.value.split("/")[1]),0,0,0).getTime();


     var today = new Date();

     today.setHours(0);
     today.setMinutes(0);
     today.setSeconds(0);
     today.setMilliseconds(0);
     today = today.getTime();

     if(vDate < today)
     {
          if (message=='') message = element.name+" faild in my test.n";
          return message;
     }
     return '';
}

 

Also note: CALENDARITEMNAME has to be replaced by your calendar item's name.

 

 

 

Special Offer

Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!