Hello,
I have an issue with the below piece of code.
I am importing a datepicker value from page 1 and store the value entered by the user into the object “datechoice”.
Page 2 (code below) shows and filters the results of a dataset (this code works well).
However, if I reload the page from a different part of the website (or if I refresh the page itself), the datepicker shows 1/1/1970 as default date. I believe this is because when the pages re-loads it imports the date directly from memory, and given that the session has been clearead the value is null / undefined. In order to sort the issue I have included the bit of code highlighted but it doesn’t seem to work. Any help on this would be greatly appreciated!
import wixData from ‘wix-data’ ;
import { session } from ‘wix-storage’ ;
$w . onReady ( function () {
$w ( ‘#citypick2’ ). value = session . getItem ( “citychoice” );
var startdate = new Date ( session . getItem ( “datechoice” )); // create a JavaScript Date object
if ( startdate === undefined || startdate === null ) {
$w ( ‘#datePicker1’ ). value = new Date ();
console . log ( $w ( ‘#datePicker1’ ). value );
}
else {
$w ( ‘#datePicker1’ ). value = startdate }
console . log ( startdate );
wixData . query ( “Rooms” )
. lt ( “availability” , startdate ) // use the startdate variable in the filter query
. and ( wixData . query ( “Rooms” ). contains ( “city” , String ( $w ( ‘#citypick2’ ). value )))
. find ()
. then ( results => {
$w ( ‘#RoomRepeater’ ). data = results . items ;
session . clear ();
});
});