Form Help

TOPIC:

Compare two calendar field values 1 year 7 months ago #234210

  • Topic Author
  • hunkiedunkie
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 10
  • Thanks: 0
Hi,

I have added 2 Calendar Elements and would like to be able to validate the second Calendar Element.

The validation would be that the 2nd Calendar's Date and Time is after the first's.

Is this possible?

Please Log in or Create an account to join the conversation.

Compare two calendar field values 1 year 7 months ago #234217

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 415
Hello,

You can take a look at this topic to see how to check if end date is after the start date as you want crosstec.org/en/forums/1-forums/123319-b...nd-datum.html#222360 .

To compare date and time elements in format "%Y-%m-%d %H:%M", do as follows.

In Validation section of 2nd Calendar Date and Time element set Validation Type to Custom and in the code area below put the following code:
function ff_cal2_validation(element, message)
{
    var Date1 = Date.parse(ff_getElementByName("cal").value); 

    var Date2 = Date.parse(element.value); 
    if ( Date1 >= Date2) {
        if (message=='') message = "Check out date must be after check in date.\n"
        ff_validationFocus(element.name);
        return message;
    } // if
    return '';
} // ff_cal2_validation
NOTE: In the code above you have to replace every instance of "cal2" with the Name of the 2nd calendar element and every instance of "cal" with the Name of the 1st calendar element

Let me know whether it works for you.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Compare two calendar field values 1 year 7 months ago #234229

  • Topic Author
  • hunkiedunkie
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 10
  • Thanks: 0
Thank you. That code works in the %Y-%m-%d %H:%M format.

But when I change to %d-%m-%Y %H:%M format is does not work right. I've looked at the other topic too but am unsure where to put in the new code and what to enter.

Please can you help?

Please Log in or Create an account to join the conversation.

Compare two calendar field values 1 year 7 months ago #234232

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 415
Hello,

The approach in code for %d-%m-%Y %H:%M format is different than in %d-%m-%Y %H:%M.

Please take a look at this example for format %d.%m.%Y %H:%M crosstec.org/en/forums/35-form-help/1259...-time-in-future.html .

If you have some programming knowledge you can adjust it for your example. In the code just replace "." separator with "-". Also, instead of comparing the date with today's date create the date element from second calendar element as well and then compare it.

Let me know whether you have managed to do so.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Compare two calendar field values 1 year 7 months ago #234239

  • Topic Author
  • hunkiedunkie
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 10
  • Thanks: 0
Hi Mihaela,

Programming is not my strong area!

Based upon the example and the previous code advice, I tried the following but fear I may be well off as my form does not recognise it!

function ff_Calendar2_validation(element, message)
{
var Date1 = Date.parse(ff_getElementByName("Calendar1").value);
var Date2 = Date.parse(element.value);
var tim = element.value.split(" ")[1];
if(tim.split(":").length != 2) {return message == '' ? "Please select time.n" : message}
var dat = element.value.split(" ")[0];
var Date1 = new Date(Number( dat.split("-")[2]),Number(dat.split("-")[1]-1),Number(dat.split("-")[0]),Number(tim.split(":")[0]),Number( tim.split(":")[1]),0).getTime();
var Date2 = new Date(Number( dat.split("-")[2]),Number(dat.split("-")[1]-1),Number(dat.split("-")[0]),Number(tim.split(":")[0]),Number( tim.split(":")[1]),0).getTime();

if ( Date1 >= Date2) {
if (message=='') message = "Check out date must be after check in date.\n"
ff_validationFocus(element.name);
return message;
} // if
return '';
} // ff_Calendar2_validation

Please can you help?

Please Log in or Create an account to join the conversation.

Compare two calendar field values 1 year 7 months ago #234262

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 415
Hello,

You were on a right track, but there are some errors in your code and missing parts.

Try using the following code:
function ff_Calendar2_validation(element, message)
{

// first calendar
    var tim1 = ff_getElementByName('Calendar1').value.split(" ")[1];
    if(tim1.split(":").length != 2) {return message == '' ? "Please select time.n" : message}
   
    var dat1 =  ff_getElementByName('Calendar1').value.split(" ")[0];

    var vDate1 = new Date(Number( dat1.split("-")[2]),Number(dat1.split("-")[1]-1),Number(dat1.split("-")[0]),Number(tim1.split(":")[0]),Number( tim1.split(":")[1]),0).getTime();

// second calendar
    var tim = element.value.split(" ")[1];
    if(tim.split(":").length != 2) {return message == '' ? "Please select time.n" : message}
   
    var dat = element.value.split(" ")[0];
    var vDate = new Date(Number( dat.split("-")[2]),Number(dat.split("-")[1]-1),Number(dat.split("-")[0]),Number(tim.split(":")[0]),Number( tim.split(":")[1]),0).getTime();


    if( vDate1 < vDate) {
          if (message=='') message = "End time must be after start time.n";
          ff_validationFocus(element.name);
          return message;
     }
    return '';
} // ff_Calendar2_validation
NOTE: Replace every instance of Calendar2 with the name of the second calendar element. Furthermore, replace every instance of Calendar1 with the name of the first calendar element.

That should compare dates in format %d-%m-%Y %H:%M .

Let me know whether it works as you wanted.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.092 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer 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!