I have a Dynamic Page that has a table in content manager. That table has a field that is Boolean. Its a true or false. There is a Dynamic Page (read-only) that is visible to clients, they can see this information, but I want to put an icon that will disappear if the boolean field is false. Visible if the boolean field is true. Basically, I want to treat it like a lightbulb that will appear only if the field is true. I might even use a text field that says “Available Now” with the same conditions (only visible if true in the boolean field). I know very little of Wix coding but I am a quick learner. Could someone help me with this conditioning coding?
I am trying this that I saw on another post but get an error and I don’t understand enough to know why…
I do something similar on my site, below is the code I use for both a dynamic page and a repeater, depending on your scenario.
You will need to change the element names to match what you have on your pages, and change “fieldKey” to be the Field Key of the column in your database you are looking for.
For dynamic page:
$w.onReady(function () {
$w("#yourDataset").onReady(() => {
var item = $w("#yourDataset").getCurrentItem();
// Change "yourFieldKey" to the Field Key of the database column you want to find
if (item["yourFieldKey"] === true) {
$w("#yourElement").show();
} else {
$w("#yourElement").hide();
}
});
});
For repeater:
import wixData from 'wix-data';
$w.onReady(function () {
$w('#yourRepeater').onReady(() => {
$w("#yourRepeater").onItemReady(($item, itemData) => {
let field = itemData.yourFieldKey; // Change "yourFieldKey" to the Field Key of the database column you want to find
if (field === true) {
$item("#yourElement").show();
} else {
$w("#yourElement").hise();
}
});
});
})
thank you @lmeyer I will definitely try this one on my page as well… I’ve been seeking help for a while trying to do the same thing. One question, if it’s not a boolean field but I want to check if the field contains a certain string, how would the IF statement look like? I guess that === should be replaced by something else?
@mitocarecenter It depends on what type of field you’re using. If you’re looking for a text field then you would replace true with the text that matches the database field in quotation marks, like below: