If field is empty (null) in dataset - How to hide a button in a repeater

HI all,

I’m slowly loosing my mind of this one. I thought it would be a simple if statement but I have tried them everywhere in the code and nothing seems to work. Can someone please help me out?

I want my the website link to hide if there is not url entered in the ShowGuide dataset, field name url.
Thanks!
Sylvia

 if (itemData.url  === ""){ 
 $item('#showLink').hide());
 }else {
 $item('#showLink').show());
 }
import wixData from 'wix-data';

const collectionName = 'ShowGuide';
const fieldToFilterByInCollection = 'menu';
// const fieldToFilterBy2 = 'SubMenu';

$w.onReady(function () {
    setRepeatedItemsInRepeater()
    loadDataToRepeater()

    $w('#menu').onChange((event) => {
 const selectedTags = $w('#menu').value
        loadDataToRepeater(selectedTags)

    })
});

function loadDataToRepeater(selectedMenus = []) {
 let dataQuery = wixData.query(collectionName)
 //let dataQuery2 = wixData.query(collectionName)

 if (selectedMenus.length > 0) {
        dataQuery = dataQuery.hasAll(fieldToFilterByInCollection, selectedMenus)
 
 // if (selectedMenus.label = ("TV Shows") { 
 //  $w('#showLink').hide());
 //  }
 
    }

 // dataQuery2
 //  .find()
 //  .then(results => {
 
 //      const itemsReadyForRepeater = results.items
 //      $w('#showGuide').data = itemsReadyForRepeater;

 //      const isUrlEmpty = itemsReadyForRepeater.url === ""

 //      if (isUrlEmpty) {
 //          $w('#showLink').show();
 //      } else {
 //          $w('#showLink').hide();
 //      }
 //  })

    dataQuery
        .find()
        .then(results => {
 
 const itemsReadyForRepeater = results.items
            $w('#showGuide').data = itemsReadyForRepeater;

 const isRepeaterEmpty = itemsReadyForRepeater.length === 0

 if (isRepeaterEmpty) {
                $w('#noResultsFound').show()
            } else {
                $w('#noResultsFound').hide()
            }
        })

}

function setRepeatedItemsInRepeater() {
 
    $w('#showGuide').onItemReady(($item, itemData) => {
        $item('#menu').tags = itemData.menu;
        $item('#subMenu').tags = itemData.submenu;
        $item('#titles').text = itemData.titles;
        $item('#description').text = itemData.description;
        $item('#showlink').link = itemData.url; 
        $item('#date').text = itemData.date; 
    })
}

Have you tried

if(itemData.url) { 
    $item('#showLink').show();
} else {
    $item('#showLink').hide();
}

THANK YOU! So simple it usually is, right!

Hello,
I’m trying to add include in my code but it doesn’t work

i replace
let dataQuery = wixData.query(collectionName)
by
let dataQuery = wixData.query(collectionName).include(colectionName2)

is this code correct?

and what is syntax for use in
function setRepeatedItemsInRepeater() ?

thank for help me

No, you should include the fieldname, not the collectionname. That fieldname is, of course, a reference field and if you include that name, the whole content of the referenced row will be inserted into the query result.

@giri-zano
thank you for the explanation. I resolved my problem