Hide duplicate cms items

Hi guys, I was wondering if anyone knew a way of hiding duplicate (in terms of a name field) items displayed in a collection list. At the moment I have created a form which allows users to submit locations, but now multiple duplicates of the locations can be submitted.

Any ideas?


Here is my public share link: LINK
(how to access public share link)

2 Likes

Hello. I have the same issue. I’m interested if you ever managed to find a solution?

1 Like

I have the same issue, how can we filter duplicate items in the dynamic list? I am using @Finsweet custom code.

1 Like

Hey All

You can use this snippet if the duplicates are based on text. Replace “.filter-component” with your own class that you wish to loop through.

document.addEventListener("DOMContentLoaded", function dumpDups() {
  const rr = new Set();
  for (const div of document.querySelectorAll(".filter-component")) {
    if (rr.has(div.textContent.trim())) {
      div.parentNode.removeChild(div);
    }
    rr.add(div.textContent.trim());
  }

  dumpDups();
});

Hope this helps ya’ll!

~ Rhino

1 Like

Hey @RhinoReign. Thanks so much for this script. It works really well on text elements. Is there any way it can be altered to find duplicates in a list of checkboxes?