HELP! Buttons in Wix repeater not following my custom code logic—some disappear after filtering, while all buttons incorrectly appear on page load instead of following visibility rules

Buttons in Wix repeater not updating correctly—some disappear after filtering, while all buttons incorrectly appear on page load instead of following visibility rules.

Question/Overview:

I am experiencing issues with button visibility in my Wix repeater on my Testimonials page.

When filtering content using a dropdown menu, the “SEE GALLERY” and “SEE PRODUCT” buttons disappear and do not reappear when the filter is removed, even when they should be visible. Additionally, when the page initially loads, all three buttons (including “NOT AVAILABLE”) are incorrectly visible by default, even though the custom code should be controlling their visibility based on the data conditions.

Product:

Wix Editor with Velo (Custom Code) – Dynamic Pages and Repeaters.

What I am trying to achieve:

I have a dynamic testimonials page where each repeater card has three overlapping buttons. These buttons should not all be visible on load; instead, their visibility should be determined dynamically based on data from my CMS and the dropdown menu (#dropdown1).

  1. “SEE GALLERY” button (#button107) should be visible if a portfolioReference field has a value.
  2. “SEE PRODUCT” button (#button109) should be visible if a productReference field has a value.
  3. “NOT AVAILABLE” button (#button110) should only be visible if neither of the above fields has a value.

What is going wrong:

However, when any filtering is applied via #dropdown1, the “SEE GALLERY” and “SEE PRODUCT” buttons disappear on all cards, even if their conditions are met, leaving a blank space where they should be visible. Meanwhile, the “NOT AVAILABLE” button continues to work correctly. Additionally, once the “SEE GALLERY” and “SEE PRODUCT” buttons disappear after filtering, they don’t return when the filter is cleared.

What I have already tried:

  • Implemented dataset filtering with code rather than relying on Wix’s dataset settings, as suggested by another developer (@dan). This is successfully filtering the repeater content but has not resolved the button issue.
  • Applied onReady to the dataset after filtering to ensure the button logic runs only after the dataset is fully loaded. However, this did not fix the issue.
  • Ensured all buttons are hidden by default before applying visibility logic to prevent them from stacking. Despite this, all buttons remain visible on page load.
  • Used console.log debugging to confirm that applyButtonLogic() runs after filtering, but the buttons still do not update correctly.

Additional information:

Here is the entire custom code for the page:

import wixData from 'wix-data';

$w.onReady(() => {
    $w('#dropdown1').onChange(() => {
        const selectedValue = $w('#dropdown1').value;

        if (!selectedValue || selectedValue === "All") {
            $w('#dynamicDataset').setFilter(wixData.filter())
                .then(() => {
                    $w("#dynamicDataset").onReady(() => {
                        applyButtonLogic();
                    });
                })
                .catch((err) => {
                    console.error("Error clearing filter:", err);
                });
        } else {
            $w('#dynamicDataset').setFilter(wixData.filter().eq("typeOfFeedback", selectedValue))
                .then(() => {
                    $w("#dynamicDataset").onReady(() => {
                        applyButtonLogic();
                    });
                })
                .catch((err) => {
                    console.error("Dataset filter error:", err);
                });
        }
    });
});

function applyButtonLogic() {
    $w("#repeater4").onItemReady(($item, itemData) => {
        $item("#button107").hide();
        $item("#button109").hide();
        $item("#button110").hide();

        const portfolioReference = itemData["portfolioReference"];
        if (portfolioReference && portfolioReference.length > 0) {
            $item("#button107").show();
        }

        const productReference = itemData["productReference"];
        if (productReference && productReference.length > 0) {
            $item("#button109").show();
        }

        if ((!portfolioReference || portfolioReference.length === 0) && (!productReference || productReference.length === 0)) {
            $item("#button110").show();
        }
    });
}

Any help in understanding

  1. why all three buttons are visible on page load, and
  2. why the “SEE GALLERY” and “SEE PRODUCT” buttons are disappearing after filtering and not reappearing when the filter is cleared would be greatly appreciated! Let me know if additional context is needed.

@Dan_Suhr I’ve created a new post that outlines everything in its current state to keep things super clear. I would really appreciate you taking a look at this as my site is currently broken until I can get this fixed! Or if you have any colleges you could ping to take a look, I would greatly appreciate it!

Hi Dawson, cool site! So there are two separate problems from what I can see:

1. “SEE GALLERY”/“SEE PRODUCT” aren’t showing up at all

When I used your code to log if applyButtonLogic() was running, I noticed that the first two portfolio/product if statements don’t work at all.

I believe this is because of the if(...&& portfolioReference.length > 0) portion. The itemData is returning an Object, which has no .length property unlike Arrays. There is a separate way to get the length of an Object.

But we actually don’t need the length at all, since this loop is going through one item at a time and pulling the data, so it should really just be one Object at a time.

So this part should work if you simply remove the && portfolioReference.length > 0 part of it, because if (portfolioReference) should already tell you if the Object exists or not.

2. Only “NOT AVAILABLE” shows up on first load

All 3 buttons are actually still on top of each other by default. This is because applyButtonLogic() hasn’t run yet – currently you’ve set it so that it only runs when an onChange happens to the dropdown. However, when the page first loads, no change event is logged by the dropdown!

You can solve this by adding a applyButtonLogic call once outside of the .onChange as well.

Let me know if this helped! :slightly_smiling_face:

5 Likes

THANK YOU! Those were indeed the problems. Everything is functioning as intended now!

1 Like