Date element (advanced)

I really don't understand the JS problem!
No error in console with this code in "Javascript code" of date element "nmne2_fb_stay___arrival_date" but alert(refDate) is not displayed, departure date doesn't change:
Code:
var to_date_id = 'nmne2_fb_stay___departure_date';  // field to fill in with the new value, actually 2020-04-25 at the opening of the page, as arrival date is this week 2020-04-19 (next sunday)
var to_date = Fabrik.getBlock('form_17').formElements.get(to_date_id);
var toDate = to_date.get('value');
var refDate = new Date(toDate); // need it to compare later
alert(refDate)
var act_date = this.get('value');   //  selected arrival date
var newDate = new Date(act_date);
alert(newDate);
var day_of_w = newDate.getDay();  // selected day of week to find the departue saturday (next if 0, else saturday of next week)
if (day_of_w === 0) {
  var diffday = 6 - day_of_w;
} else {
  var diffday = 13 - day_of_w;
}

newDate.setDate(newDate.getDate() + diffday);  // add days to new departure date

to_date.set(newDate);
Advanced tab of departure date:
Code:
var diff = new Date().compare(new Date(date));
var result = diff < 0 ?true : false;

If I leave empty the advanced tab of departure, I have this in the console
date-min.js:3 Uncaught ReferenceError: result is not defined
at Object.dateSelect (date-min.js:3)
[/CODE]
 
Did you clear your browser cache to get modified JS after every modification?
It's all working fine on my site.
 
Yes, I use CTRL+F5
That's why I say I don't understand.

If I unpublish the javascript in arrival and use this code in advanced tab of departure, the selected day in the calendar changes, the allowed days begin on calculated departure, but the problem is the same: I need to click on the departure calendar icon to see the change in the displayed field (but the calendar doesn't display the month of the new departure date), and click another time for the calendar to show the right calendar window and departure date. (I can give you the address of this test site by PM)
Code:
var from_date_id = 'nmne2_fb_stay___arrival_date';
var from_date = Fabrik.getBlock('form_17').formElements.get(from_date_id);
var fromDate = from_date.get('value');
var refDate = new Date(fromDate);
var day_of_w = refDate.getDay();  // selected day of week to find the departue saturday (next if 0, else saturday of next week)
if (day_of_w === 0) {
  var diffday = 6 - day_of_w;
} else {
  var diffday = 13 - day_of_w;
}

var selDate = new Date(refDate);
selDate.setDate(refDate.getDate() + diffday);
selDate.increment('day', diffday);

this.set(selDate);

var diff = new Date(selDate).compare(date);
var result = diff < 0 ?true : false;
 
Last edited:
Sorry, I had sometimes this menu but can't actually open it :(

Thanks for your help! I hope I will finally reach the end! ;)

I created a new list for testing and it's correct.
date element "arrival",
default date OK:
Code:
date_default_timezone_set('UTC');
if (date('w',strtotime('now')) == 0) {
$date_dep = date('Y-m-d',strtotime('Saturday next week + 1week'));
} else {
$date_dep = date('Y-m-d',strtotime(' next week Saturday'));
}
return ($date_dep);
advanced tab:
Code:
var diff = new Date().compare(new Date(date));
var result = diff < 0 ?true : false;
Javascript
Code:
var to_date_id = 'nmne2_fb_test_calendar___departure';
var to_date = Fabrik.getBlock('form_18').formElements.get(to_date_id);
var from_date = this.get('value');
var newDate = new Date(from_date);
newDate.increment('day', 6);
to_date.set(newDate);
Now I need to compare and try to understand why the others ate elements don't work, then add calculations for days and durations, allowed departure dates...
 
Hi,

It works now ! :)
Many thanks for your help, troester.

I need to add other calculations when these dates change.
 
Oh sorry, it works with 3 "alert" in Javascipt fo arrival. As soon I comment one of them, the departure date doesn't change. :(
This code works
var to_date_id = 'nmne2_fb_test_calendar___departure';
var to_date = Fabrik.getBlock('form_18').formElements.get(to_date_id);
var from_date = this.get('value');
var newDate = new Date(from_date);
newDate.increment('day', 6);
alert(newDate);
to_date.set(newDate);
This code doesn't work
var to_date_id = 'nmne2_fb_test_calendar___departure';
var to_date = Fabrik.getBlock('form_18').formElements.get(to_date_id);
var from_date = this.get('value');
var newDate = new Date(from_date);
newDate.increment('day', 6);
//alert(newDate);
to_date.set(newDate);
 
Hmm, yes. It's in the tooltip
Javascript inline code.
Note: Do not use // style comments in this code, as newlines will be stripped so everything after the first // will become commented out.
/* These comments */ work fine. A descriptive comment on the first line will appear in the heading.
 
Sorry, I didn't see the tooltip, only the header
upload_2020-4-16_22-40-30.png
For me, this text says that I can use "//"

PS: I think it would better to write "Warning: Code must NOT contain inline comments //", no?
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top