TOPIC:

Calendar function to have a warning message when you choose past departure date 1 month 1 week ago #260523

  • Topic Author
  • gkukovacec
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 57
  • Thanks: 0
Hello,I have 2 calendars, first one is Arrival, second for departure. I want to accomplish that if I choose arrival date for example, 18.06.2021., I cannot pick 23.05.2021, cuz that's past date. Is it possible to accomplish that?I'm sending a screenshot of the current situation which is not good.Regards,M
Attachments:

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

Last edit: Post by gkukovacec.

Calendar function to have a warning message when you choose past departure date 1 month 1 week ago #260524

  • Mirec's Avatar
  • Mirec
  • Offline
  • Gold Breezer
  • Gold Breezer
  • Posts: 454
  • Karma: 2
  • Thanks: 19
Hi,

yes, you can do it, could you please look at the link below where is all described.

crosstec.org/en/support/online-documenta...ating-past-date.html

If you get stuck let me know and I'll help you!
regards,
Mirko

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

Last edit: Post by Mirec.

Calendar function to have a warning message when you choose past departure date 1 month 1 week ago #260556

  • Topic Author
  • gkukovacec
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 57
  • Thanks: 0
But that's function where you cannot pick past date and that's not exactly what I need...
I need to connect somehow first (Arrival calendar) and second (Departure calendar), so If costumer choose arrival date for example 16.06.2021., they cannot select a date that was before picked arrival date.
So yeah, I'm pretty stuck here huh

Regards,
M

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

Calendar function to have a warning message when you choose past departure date 1 month 1 week ago #260561

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Posts: 6455
  • Karma: 3
  • Thanks: 456
Hi,

I create a small example for you (please download->unzip and install it).

File Attachment:

File Name: Example_20...6-18.zip
File Size:8 KB


I added two calendars (format %d.%m.%Y).

Arrival calendar has name calendar1
Departure calendar has name calendar2

1) In calendar1->Propertis->Validation->I added this:
function ff_calendar1_validation(element, message)
{
    var pattern =  /[0-3][0-9]\.(0|1)[0-9]\.(19|20)[0-9]{2}$/;
   if(pattern.test(element.value) || element.value != '') return '';
        if (message=='') message = element.name+" faild in my test.\n"
        ff_validationFocus(element.name);
        return message;
} // ff_calendar1_validation
This code check if date is in correct format, and if date is not in correct format or empty error message is shown on submit.
Please replace calendar1 with name for your arrival calendar (not title)

2) In calendar2->Properties->Validation->I added this:
function ff_calendar2_validation(element, message)
{
    // Checking if the entered date is in right format
   var pattern =  /[0-3][0-9]\.(0|1)[0-9]\.(19|20)[0-9]{2}$/;
   if(pattern.test(element.value))
   {
      var date_array = element.value.split('.');
      var day = date_array[0];
 
      // Attention! Javascript consider months in the range 0 - 11
      var month = date_array[1] - 1;
      var year = date_array[2];
 
      // This instruction will create a date object
      var startDate = new Date(year,month,day);
 }
    
   var calend2=ff_getElementByName('calendar1').value.split("."); 
   var d2= new Date(calend2[2], calend2[1]-1, calend2[0]); 
   var dan=d2.getDate();
   var mj=d2.getMonth();
   var god=d2.getFullYear();
   var end=new Date(god,mj,dan);
   
   if (startDate < end || element.value == '') {
       if (message=='') message = "Departure date can't be before then arrival date or be empty .\n"
       ff_validationFocus(element.name);
       return message;
   } // if
return '';
} // ff_calendar2_validation
This code check if date is in right format, and check if user select a date that was before arrival date. If arrival date is 16.06.2021, and departure date is 15.06.2021, on submit error message will be shown

In this part:
var calend2=ff_getElementByName('calendar1').value.split("."); 
calendar1 is name of arrival date (not title), replace it with yours
calendar2 is name of depature date (not title), replace it with yours

Let me know if you need more help

Regards,
Tihana
Attachments:

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

Last edit: Post by tihana.krivic.

Calendar function to have a warning message when you choose past departure date 1 month 1 week ago #260575

  • Topic Author
  • gkukovacec
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 57
  • Thanks: 0
Thats working perfectly, thank you!

Just one more question, costumer has one more wish, if it's possible of course... is it possible to accomplish that on the departure calendar, all days before picked arrival date should be grayed out and cannot be actually selected, or something similar like that?

Here's an example: www.booking.com/index.hr.html

Regards,
M
Attachments:

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

Calendar function to have a warning message when you choose past departure date 1 month 1 week ago #260577

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Posts: 6455
  • Karma: 3
  • Thanks: 456
Hi,

this can be done with responsive calendar

1) add two responsive calendar to your form
2) go to your form->Advanced->More options->Scripts->Initialization Script->check Custom and put this:
function ff_nameofform_init()
{

 jQuery('.bfCalendar').remove();
    
   jQuery('[name="ff_nm_nameofarrivalcalendar[]"]').pickadate({
 min: true
})


var from_$input = jQuery('[name="ff_nm_nameofarrivalcalendar[]"]').pickadate(),
    from_picker = from_$input.pickadate('picker')

var to_$input = jQuery('[name="ff_nm_nameofdeparturecalendar[]"]').pickadate(),
    to_picker = to_$input.pickadate('picker')


// Check if there’s a “from” or “to” date to start with.
if ( from_picker.get('value') ) {
  to_picker.set('min', from_picker.get('select'))
}
if ( to_picker.get('value') ) {
  from_picker.set('max', to_picker.get('select'))
}

// When something is selected, update the “from” and “to” limits.
from_picker.on('set', function(event) {
  if ( event.select ) {
    to_picker.set('min', from_picker.get('select'))    
  }
  else if ( 'clear' in event ) {
    to_picker.set('min', false)
  }
})
to_picker.on('set', function(event) {
  if ( event.select ) {
    from_picker.set('max', to_picker.get('select'))
  }
  else if ( 'clear' in event ) {
    from_picker.set('max', false)
  }
})
}
When you click on calendar input field you will see calendar with disabled dates (dates are nonselectable)

Please replace:
-nameofform with name of your form (not title)
-nameofarrivalcalendar with name of your arrival calendar (not title)
-nameofdeparaturecalendar with name of your deparature calendar (not title)


P.S: this can't be done with calendar, only with responsive calendar.
If you are using calendar then only on submit you will see error message (using code from message above)

Regards,
Tihana

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

Last edit: Post by tihana.krivic.
Time to create page: 0.053 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!