PricingBlog

How to prevent duplicates in repeated options in select

  • toddledoodle-1276161116615082004

    m

    1 year ago

    Hello! I am trying to filter my repeated list using a select element. I want the options in the select to be dynamically rendered from an enum with predefined options. How do I make the enum options not displayed more than once in the select element even if they appear multiple times in the database? I tried using the unique() formula in different ways but I couldn't get it to work correctly.
  • jacobkofoed-1276169738904408209

    Jacob Kofoed

    1 year ago

    Can you share a screenshot of how you're doing this? The Unique formula usually works well for this exact problem 🤔 Perhaps each item has a unique field (id or something) that prevents unique from working.
  • toddledoodle-1276172130215792732

    m

    1 year ago

    @Jacob Kofoed Yes! I tried a few different ways, but this is the latest. What did I do wrong?
    1276172129314017361-Screenshot_2024-08-22_at_9.27.46_AM.png
    1276172129900957696-Screenshot_2024-08-22_at_9.27.06_AM.png
    1276172129565540402-Screenshot_2024-08-22_at_9.27.28_AM.png
  • jacobkofoed-1276172510982832222

    Jacob Kofoed

    1 year ago

    If you just need to show the name of the books, then you could do something like API-data -> Map item.book -> Unique then you will have a flat Array of book titles.
  • So first Map. Unique works by checking the whole object, so if the data from your database has some unique ID etc. it won't work
  • toddledoodle-1276172863073812582

    m

    1 year ago

    I think I tried that, using map, but didn't show up right. Let me try that now.
  • toddledoodle-1276173433087983667

    m

    1 year ago

    @Jacob Kofoed oh wow it works! That's funny, I must have made a mistake somewhere when I tried that earlier. Thank you so much for your help!!!
  • jacobkofoed-1276174604485787699

    Jacob Kofoed

    1 year ago

    Awesome, glad it worked 👏
  • toddledoodle-1276301427442192404

    m

    1 year ago

    I kind of have a follow-up problem. After creating the select and rendering the options correctly thanks to @Jacob Kofoed, I am trying to filter a list based on the option selected in the select element. So I created a variable with an empty string ""to hold the value and add a 'change' event. But no matter which options I select, the variable only shows "option1". Here are some screen shots. @Jacob Kofoed or anyone, what did I do wrong?
    1276301426510921738-Screenshot_2024-08-22_at_5.55.22_PM.png
    1276301426745938041-Screenshot_2024-08-22_at_5.55.50_PM.png
    1276301426976493619-Screenshot_2024-08-22_at_5.56.49_PM.png
    1276301427244925021-Screenshot_2024-08-22_at_5.57.03_PM.png
  • tomthebigtree-1276304959398215798

    Tom Ireland

    1 year ago

    I think (but don't quote me as it's from memory) you need your change event on the <select> element as opposed to the <option>.
  • toddledoodle-1276311500255924295

    m

    1 year ago

    Hey @Tom Ireland , thanks for responding! It was on the <select> element and just to test it I tried on the <option>, still same issue, showing "option1" as the value. 🤨
  • lucasg-1276312431098069002

    Lucas G

    1 year ago

    On the option element, go to the attributes tab
  • You'll see a value attribute in there, go in and make sure it is the 'item' you are repeating over
  • toddledoodle-1276318982726619267

    m

    1 year ago

    That totally works @Lucas G , thank you! I put the value in the wrong place 😬 You guys are so very helpful!!!
    👍2
  • Tod-1276318983813070890

    Tod

    1 year ago

    Great energy @m! Your continuous contribution to the toddle Community just made you advance to Community Level 2!
  • lucasg-1276320182234644551

    Lucas G

    1 year ago

    You’re welcome
  • lucasg-1276320564256051271

    Lucas G

    1 year ago

    You didn’t necessarily put it on a wrong if you’re referring to the change action. It’s just that when you’re repeating the options, the value is no longer static so it needs one extra step
  • Seems like you did everything correctly though ✌️
  • toddledoodle-1276334709625847850

    m

    1 year ago

    @Lucas G I was putting the value attribute in the <select> . Coming from a design background, this is definitely a steep learning curve for me. I am thankful for all the help I got from you all!