Hide button boolean wix database

Hi Guys.

I have a repeater linked to a dataset and the dataset linked to a database. In the repeater i have 2 buttons - one for links and one for files. When you enter a link in a post it will make it “true” in my boolean data column “knapURL”. When you enter a file it will make it true in boolean column “knapPDF”. And ofcourse they will be false if not entered.
I then want to hide the button “#button1” which is linked to “knapPDF” when it is false and vice versa. Ive tried this solution, but sadly it dosn’t work :frowning:


I hope you guys can help me! Thanks alot.

1 Like

Hi Alexander,

You can only have only onItemReady() function for a repeater. If you have more than one, then only the last one is used.

Yisrael

1 Like

Hi Yisrael

$w.onReady(function () {
//TODO: write your page related code here…
});

$w(“#repeater1”).onItemReady( ($w, itemData, index) => {
console.log(itemData.pdfknap);
if(itemData.pdfknap === “yes”) {
$w(“#button1”).show();
}
else {
$w(“#button1”).hide();
}
});

So i tried this now and it doesnt work. Let me say that i can’t code at all, and i’m just trying to figure this out here on the forurms. I get these messages


And i get this little yellow triangle on the left side of the code line saying “parameter index is never used”
I appriciate your help, thanks alot!
Alexander

The error “cannot be used before the page is ready” is because your code needs to be inside of the $w.onReady() , which means the page is ready.

The message with the little yellow triangle is only a warning.

1 Like

Hi Yisreal - first of all, thank you very much for your help! :slight_smile:
I’m making the homepage together with Alexander.


Our database has this “Knappdf” boolean, and as you can see the boolean is “true” at the first 4 rows.


Next step is the coding… I’ve removed the last onItemReady() function and put the $w(“#repeater1”).onItemReady inside the onItemReady() function…
I hope i did it correctly?
It look like this:


But when I preview the site, all of the buttons are hided, not just the two ones with “no” in the boolean and also i’m not having any error messages…


Im not sure if i did something wrong… We hope so much that you can spot the mistake :slight_smile:
Best regards Alexander and Magnus

1 Like

Yisreal please let us know if you need more information :slight_smile:

You need to be sure that the collection field keys are correct. Other than that, I don’t see anything.

Please post the URL of your site and I’ll see if I can spot something. Only authorized Wix personnel can get access to your site in the editor.

The field key is correct and the link is as followed: https://alexanderweidinger.wixsite.com/segaf/nyehder.
It was the wrong picture we posted before, this is how it looks now. And it still hides all the buttons.

$w.onReady(function () {

$w(“#repeater1”).onItemReady( ($w, itemData) => {
console.log(itemData.knappdf);
if(itemData.knappdf === “yes”) {
$w(“#button1”).show();
}
else {
$w(“#button1”).hide();
}
});
});

How about the connection between button 1 and the boolean collum, should there be any, except for the connection in the database? Right know we have it connected to a pdf collumn in the dataset and if it cotains a pdf the boolean column is marked “true”, but the button can’t be connected with the boolean, which i guess makes sense.

Thanks again, ill hope you will find something!

Aha! I discovered the problem. The if statement should be:

if (itemData.knappdf === true) {

Wow! Can’t believe I missed that. I hate it when I’m stupid. The value in the knappdf field is a boolean and not a string. Therefore, no quote marks around true.

Yisrael

2 Likes

It works
Thank you so much Yisrael. you are the best! We truly appreciate your effort and help. Once again thank you!

Hi,

I tried the following code but It always shows “Closed” no matter what the value of the boolean is

import wixData from ‘wix-data’;

$w.onReady( function () {

$w(“#repeater1”).onItemReady( ($w, AmbCamp) => {

console.log(AmbCamp.campaignStatus);     

if (AmbCamp.campaignStatus === “true”) {

    $w("#openCampbutton").label = "Open"; 

} 

else {

    $w("#openCampButton").label = "Closed"; 

} 

        }); 

});

Did you see my previous post? Is the field campaignStatus a boolean? If so, then no quote marks around true .

@yisrael-wix Duuh you’re right! is not a string value :slight_smile:
Thanks!

1 Like

Good afternoon I am writing about this code, I have a database with multiple restaurants and I need to show a reservations button if they offer online reservations. I have a field restReservationsLink as a boolean value and my button is button5 which is the one i need to show or not based on boolean…but for some reason it does not work…

$w . onReady ( function () {
$w ( “#repeater2” ). onItemReady ( ( w$ , itemData ) => {
console . log ( itemData . restReservationsLink );
if ( itemData . restReservationsLink === true ){
$w ( “#button5” ). show ();
}
else {
$w ( “#button5” ). hide ();

}
});
});

You need to use the Repeated Item Scope for elements in the Repeater (e.g. #button5). You want something like this:

$w.onReady(function () {
    $w("#repeater2").onItemReady(($item, itemData) => {
        console.log(itemData.restReservationsLink);
        if (itemData.restReservationsLink === true) {
            $item("#button5").show();
        }
        else {
            $item("#button5").hide();
        }
    });
});

Also, note that in the onItemReady your original code has a typo of w$.

Thanks for the quick response, I actually made a detail page that connects to my repeater, www.dineupnj.com is my website…please take a look and please comment

Happy New Year