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.
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();
}
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…