Dear all,
I would need help with transferring a value collected from a date picker on page 1 to another date picker on page 2. I have found a similar post but it does not seem to work for me.
The code I currently have is:
On page 1:
import {session} from 'wix-storage'; // activates wix-storage import wixlocation from 'wix-location'; $w.onReady(function () { //DROPDOWN FILTER $w('#searchbutton').onClick(() => { session.setItem("citychoice", $w("#citypick").value); let startdate = String($w('#datePicker1').value); session.setItem("datechoice", startdate) wixlocation.to("/rooms"); }); });
On page 2:
import wixData from 'wix-data';
import { session } from 'wix-storage';
import wixLocation from 'wix-location';
//IMPORT VALUES AND FILTER $w.onReady(function () { $w('#citypick2').value = session.getItem("citychoice") var startdate = new Date(session.getItem("datechoice")); $w('#datePicker1').value = startdate; wixData.query("Rooms") .lt("availability", $w("#datePicker1").value) .and(wixData.query("Rooms").contains("city", String($w('#citypick2').value))) .find() .then(results => { $w('#RoomRepeater').data = results.items; session.clear(); }) The above code works for the first condition (i.e. city choice, but not for the date picker, whose value is not passed to page 2)
Any help on this would be highly appreciated.
Alessandro
Thank you very much, it works now!
Hi!
Page 1:
import {session} from 'wix-storage'; // activates wix-storage import wixlocation from 'wix-location'; $w.onReady(function () { //DROPDOWN FILTER $w('#searchbutton').onClick(() => { session.setItem("citychoice", $w("#citypick").value); let startdate = String($w('#datePicker1').value); console.log(startdate); // log the date picker value to the console session.setItem("datechoice", startdate); wixlocation.to("/rooms"); }); });
Page 2:
import wixData from 'wix-data'; import { session } from 'wix-storage'; import wixLocation from 'wix-location'; $w.onReady(function () { $w('#citypick2').value = session.getItem("citychoice"); var startdate = new Date(session.getItem("datechoice")); // create a JavaScript Date object console.log(startdate); // log the date value to the console $w('#datePicker1').value = 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(); }); });
If you get Errors, write it that i can better understand what the problem is :)