How to hide button if database field is empty

Hello. Newbie to Code here. I have a conference speaker presentations page at https://www.productcamprtp.org/speaker-applications

Some of the presenters have not provided a PDF file of their presentation yet. The field in my Speaker-presentation database is called “presentation”. The button on the page is button1. How do I use Wix Code to hide button1 if the presentation field is empty? I’ve been through many similar questions in this forum, but nothing quite like this. Seems like a simple thing to do, but apparently not. :frowning:

Thanks for the help!

Shelly

Hello Shelly,
I did the same in my code. It is a little bit tricky because the code has to be executed only when the dataset is loaded. So here it is (my dataset is called dynamic dataset):

import wixData from ‘wix-data’;

$w.onReady( () => {
$w(“#dynamicDataset”).onReady( () => {
let currentItem = $w(“#dynamicDataset”).getCurrentItem();
let presentationElement = $w(“#button1”);

if ( currentItem.presentation === undefined) {
presentationElement.hide();
presentationElement.collapse(); // set height to 0
} else {
presentationElement.show();
}

} );

} );

Good luck!
Franziska

Thank you Franziska. I am getting an error that my dataset name is not a valid selector. I’ve tried renaming it to not have a dash, didn’t help. Here’s what it says:

import wixData from ‘wix-data’;

$w.onReady( () => {
$w(“#Speaker-submission”).onReady( () => {
let currentItem = $w(“#Speaker-submission”).getCurrentItem();
let presentationElement = $w(“#button1”);

(the rest is in there)

When I preview, I get these errors in the code area:

TypeError: $w(…).onReady is not a function
Speaker Applications
Line 5
Ev-Widget: Error handler
Ev-Widget: viewer.ts
Ev-Widget: Error handler

Perhaps a “-” inside the dataset name ist not valid?? Try renaming your dataset (via right click in it; then properties at the bottom; then change the name inside the upcoming properties-panel) – perhaps to speakerSubmission…

hey thank you for sharing you code i have use this code but mine is stay hidden even if i switch the code i hope you can help me with this problem

have you ever solved this ? I am having the same issue

I used this code but it is collapsing all buttons even though I have 1 of the buttons pointing toward a url in the data set. Ideas on Troubleshooting?