Velo: wixData line seems to be automatically disabled

Question:
Why does my line of code for wixData seem to be automatically disabled.

Product:
Wix Editor

What are you trying to achieve:
First of all, I am not a Velo developer so I apologize if this is really basic. I am trying to set the url of a vector image based upon the value of a text field. Both fields are in a Repeater.

When I implement the code I know that I need the line “import wixData from ‘wix-data’;” though when I add that line of code it looks like it is automatically disabled (the text is a lighter shade). You can see this in the image of the page code.

Any idea on why this is happening and suggestions on how to resolve it?

Additional information:

You are importing a function that is not being called in your code, that is why the text is lighter in color. You’d need to call the function in order to use it. For example:

function findItem(id){
    wixData.query("MyCollection").eq("_id",id).find().then((results)=>{
        console.log(results.items)
})
}

However, based on your post, it seems like your repeater is connected to a dataset element and is not being populated by code. If that is the case, then you do not need to import wixData, as the data is already available. To access this data in code, use the repeater’s onReady method and place this somewhere in the Page’s onReady function:

$w.onReady(async function(){
    let lang = wixWindow.multilingual.currentLanguage;
    let deviceType = wixWindow.formFactor;
    await $w("#repeater1").onReady(($item,itemData,index)=>{
        //when the page has loaded, the repeater will be filled with items from the dataset element it is connected to
        if(lang == "en"){
            $item("#image3").src = "url1";
        } else if (lang == "fr"){
            $item("#image3").src = "url2";
        }
        if (deviceType == "Tablet"){
            $item("#image3").hide();
        }


    })
}

As for the second part of your code, it seems as if you are attempting to change the SRC of a vector image based on a checkbox. However, your code seems to indicate the variable “textfieldValue” that you are testing for truthiness is actually a string, not a boolean value. Strings of text are returned from text input elements and boolean values are returned from checkboxes. The code is using “textfieldValue” as both a string (to set the $w(“#text203”).text value) and as a boolean (checking to see if “textfieldValue” is true, which it always will be as long as there is text within the string). There may be a conflict in the code.

Thanks very much for the detailed review. Greatly appreciated!

1 Like