Disable button if it's empty on database

Hello, I am making a page where it have buttons that are connected to my database (Document). I want if on the database is empty (no document attached to the item) the button disabled.

I’ve tried this code, it did disabled the button if its empty, but if there is a document, it just can not click.

$w.onReady(()=>{ 
    $w("#dataset1").onReady(()=>{ 

      let myData = $w("#dataset1").getCurrentItem().pricelist; console.log(myData)
if (myData === 'Yes') {$w('#button7').enable();}
else{ $w('#button7').disable(); } 
   
   });
});

What did i miss? Thanks

@vuerarealestate You want to check for the myData variable (pricelist) being undefined. You would do that like this:

$w.onReady(()=>{
  $w("#dataset1").onReady(()=>{
    let myData=$w("#dataset1").getCurrentItem().pricelist;
    console.log(myData)
    if (myData){
      $w('#button7').enable(); 
    } else {
       $w('#button7').disable();
    }
  });
});
1 Like

I’ve tried your code, I find that the possible reason it can not be clicked is because the button redirects the click action to wix editor, not the supposed document (pdf)

this is the redirect link if using my code & your code (red arrow)

this is the supposed redirect link (a pdf file)

is there any ideas / workaround? Thanks

Amazing, this code actually works. Thank you so much!