velo

Prefill dropboxes based on user selection from prior page


I cannot get the drop-boxes to fill from the users selection on the prior page - can someone help?

Prior page code saving the values:

export function button43_click(event) {
        session.setItem("statehome",$w('#dropdownstate').value);
        session.setItem("lakehome",$w('#dropdownlake').value);
        wixLocation.to("https://www.laketoads.com/import-791")

Current page code trying to set the default value to the user's selections:

import {session} from 'wix-storage';
import wixData from 'wix-data';

$w.onReady(function () {

    $w('#stateDropdown').options = [];
    $w('#lakeDropdown').options = [];

    $w('#stateDropdown').onChange((event) => {
        populateLakeData(event.target.value);
    });

    populateStateData();

    const selectedstate = session.getItem("statehome");
    $w("#stateDropdown").value = selectedstate;
    const selectedlake = session.getItem("lakehome");
    $w("#lakeDropdown").value = selectedlake;
});

Can anyone help? - I've tried both local and session code and am stuck.


Solution

  • Use the dataset setFilter() function instead of refreshing. Set the filter to the values in the dropdowns. You will need to refilter when the dropdowns change as well.