Hi Everyone. So i’ve been using the code queens tutorials to have three dropdown menus filter through to get to a unique choice made by the user. This all works fine. I then want to use the users final choice to link to a url in my dataset. Again I used the code queens code. I used console.log() to check to see if the url was correct which see image blow, however i get the error listed above saying the parameter needs to be a string. I tried changing the dataset field type from url to text, but the error was still there. Any help would be awesome as I have been sitting here for hours now trying to figure it out. Thanks in advance.
Karl
I am not sure here but I guess u are assigning the object itself as the the url parameter. Actually it will be yourobjectname[0].yoururlfieldID…
I hope you understand what I mean …
If you’re using a tutorial, doesn’t it show you what you need to do?
In any case, you will need to provide more details in order for us to help. Please share the relevant code (using a code block in your post), explain what you’re doing, and what’s not working.
Thank you for your quick reply. I’m using the code from the code queens tutorial called “Use dropdowns to Navigate to a different page” (it wont let me post the link) my edited code of this is below.
The video below explains what i am trying to do. Sorry for the low quality needed to keep it under 50mb
Many thanks for your help.
$w.onReady(function () {
$w("#halftermdropdown").onChange((event) => {
let title = $w('#halftermdropdown').value; //This line gets the current Title value of the dropdown option that was selected.
$w("#filter").onReady(() => {
console.log("The dataset is ready to be filtered."); //This line tells us our dataset is ready to be filtered.
$w("#filter").setFilter(wixData.filter()
.eq("halfTerm", title) //This line looks for matching titles in the database collection so that now it is only displaying 1 result
)
.then(() => {
console.log("To filter dataset is now filtered with the matching title from the dropdown.");
let getItem = $w("#filter").getCurrentItem(); //This line gets the 1 result we should have in our filtered dataset
let url = console.log(getItem.link); //This line gets the URL field for that 1 result
console.log(wixLocation.to(url)); //This line redirects us to the URL
})
.catch((err) => {
console.log(err);
});
});
});
});
You aren’t using console.log() correctly. For example, in this line:
let url = console.log(getItem.link);
The variable is being set to whatever it is that the function console.log() returns, which as far as I know, is the value null.
More likely what you need is something like this:
let url = getItem.link;
console.log(url);
Which will set the value of url to the link, and then display the value of url in the console.
I have no idea what this line actually does:
console.log(wixLocation.to(url));
However I suspect that it will relocate to the value in url, and will also most likely display nothing in the console.
I would suggest checking with the Code Queen if you are having difficulties since this is her tutorial.
Hi guys. Thank you so much for your help. Turns out it works live and I was in preview mode. So all sorted. Why is that the case though?