Error Message on Dynamic Page Loop

I am following a tutorial made by @yisrael-wix on https://www.grampsworkbench.com/ for a dynamic page loop. However, when I get to the end/beginning of the pages I am receiving an error and it won’t loop to the beginning or end. I’ve swapped out all the information I need to do, and have set up the page correctly.

I have attached the code below.

The error I am getting is Wix code SDK error: The url parameter that is passed to the to method cannot be set to the value . It must be of type string.

This is happening on lines 19 and 33 - wixLocation.to(res);

Help is much appreciated.

import wixLocation from 'wix-location';

$w.onReady(function () {
  $w("#workDataset").onReady(() => {
    const numberOfItems = $w("#workDataset").getTotalCount();
    $w("#workDataset").getItems(0, numberOfItems)
      .then( (result) => { 
        const dynamicPageURLs = result.items.map(item => item['projectName']);
      } )
      .catch( (err) => {
        console.log(err.code, err.message);
      } );
  } );  
});

export async function btnPrev_click(event) {
    let res = await $w("#dynamicDataset").getPreviousDynamicPage();
    if(res !== null) {
        wixLocation.to(res);
    } else {
        let count = $w("#workDataset").getTotalCount();
        await $w('#workDataset').setCurrentItemIndex(count);
        let item = await $w('#workDataset').getCurrentItem();
        let work = item.projectName;
        work = work.replace(/ /g, '-');
        wixLocation.to('/work/' + work);
    }
}

export async function btnNext_click(event) {
    let res = await $w("#dynamicDataset").getNextDynamicPage();
    if(res !== null) {
        wixLocation.to(res);
    } else {
        await $w('#workDataset').setCurrentItemIndex(0);
        let item = await $w('#workDataset').getCurrentItem();
        let work = item.projectName;
        work = work.replace(/ /g, '-');
        wixLocation.to('/work/' + work);
    }
}

Edit: Ignore the “solution” in this this comment. It was the result of a major brain fart. See my followup comment .

Wow! Seems like something changed in between glasses of Guinness. In fact, my original code isn’t really correct. It should be checking if there is in fact a prev or next page before trying to get the page URL.

The correct code for the prev and next buttons should be:

export async function btnPrev_click(event) {
    let isPrev = await $w('#dynamicDataset').hasPreviousPage();
    if(isPrev) {
        let res = await $w("#dynamicDataset").getPreviousDynamicPage();
        wixLocation.to(res);
    }
    else {
        let count = $w("#dataset1").getTotalCount();
        await $w('#dataset1').setCurrentItemIndex(count);
        let item = await $w('#dataset1').getCurrentItem();
        let country = item.title;
        country = country.replace(/ /g, '-');
        wixLocation.to('/countries/' + country);
    }
}

export async function btnNext_click(event) {
    let isNext = await $w('#dynamicDataset').hasNextPage();
    if (isNext) {
        let res = await $w("#dynamicDataset").getNextDynamicPage();
        console.log('res', res);
        wixLocation.to(res);
    } else {
        await $w('#dataset1').setCurrentItemIndex(0);
        let item = await $w('#dataset1').getCurrentItem();
        let country = item.title;
        country = country.replace(/ /g, '-');
        console.log('country', country);
        wixLocation.to('/countries/' + country);
    }
}

I’ll fix the example as soon as I get a chance. Sorry for the inconvenience.

Thanks for that. A real help. The only problem I am now facing is when I click on the next button it’s loading a page without any information from the dataset (Looks like a dynamic page built from the editor)

When you click the next button again it’s saying Operation (hasNextPage) is not allowed because the field used to build this page’s URL is empty and is doing the same for the previous page button. The field that creates the URL has information, but I’m guessing because it’s bringing up a page without any content, then it has no information to build a URL for the next page from

@noahlovell Note: the code I posted is the corrected code for my example. Make sure you make the appropriate adjustments for your site.

OK - so I had a major brain fart. Forget my previous post. I reworked the example with the correct code. Take a look at it again and not the changes. Sorry.

1 Like

Awesome! These things happen, but I’m glad to say that it is working now!

Legend :facepunch:

One last thing, I know it’s not strictly code related, but I see that on your site there is a load template, which creates a copy of the site in the persons account of who opens it. Is this something that is only available to Wix staff or possible for anyone to create?

@noahlovell Templatizing a site is currently only available to Wix personnel. However, the possibility of opening it up has been discussed. You can request this feature on the Wishlist Page which is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.