Hi guys,
I have been trying for a couple of days and I would really appreciate some help with passing variables across pages when it comes to dates. Here is what I am trying to achieve:
-
On the 1st page: a date picker lets the user pick up a date, then a “Search” button directs the user to a 2nd page
-
On the 2nd page: the variable from 1st page is passed to page 2, assigned to another date picker (which shows the value initially entered by the user on the 1st page), and a collection from a dataset is retrieved and filtered by date (according to the date value entered on page 1) and showed on page 2 through repeaters
The code that I am using is:
On 1st page:
import {session} from ‘wix-storage’; // activates wix-storage
export function button_click(event, $w) { // on click…
let start = $w(“#datePicker1”).value; // assigns datepicker value to start variable
session.setItem(‘startdate’, start); // stores start variable using startdate key
}
On 2nd page:
import wixData from “wix-data”; // activates wix-data
import {session} from ‘wix-storage’; // activates wix-storage
$w.onReady(function () {
let start = session.getItem(‘startdate’); // retrieves start variable from page 1 (WORKS)
$w(‘#datePicker2’).value = start; // assignes start value to datepicker on page 2 (DOESN’T WORK, I would like to have the value from page 1 passed to and showed in the new datepicker)
let e = $w(“#datePicker2”).value; // assigns datePicker2 value to variable e
e.setHours(0,0,0,0); // clears out the time from e
$w(“#RoomsDS”).setFilter( wixData.filter() // filters the dataset RoomsDS by date
.lt(“availability”, e));
session.clear(); // clears the session
});
To be noted: All the filtering code works well when it is run from page 2, with a date selected by the user directly into datePicker2. It is when I try to get the stored data from page 1 and assign it to datepicker2 (page 2) that somethings is not working…Anything I should do to set up datepicker2 in order to be able to “accept” data instead of running with today’s date or blank?
Any help is appreciated!
Alessandro