Help forum

Repeat item within a component in a repeat item is getting the wrong attribute

  • Victor Giron

    2 years ago

    Hey guys! I'm having this issue:

    I have a table in the page, within each row I have a component called dropdown-status, which receives the statusid from the row.

    Inside the component I have a list of statuses coming from an API call within the component. I want to mark the selected status based on the attribute "statusid" I'm passing from the outside table.

    When I test it inside the component it works, but when I test it from the outside table all the components of the rows are receiving the first-item statusid instead of each row's statusid.
  • gazinhio

    2 years ago

    I'm doing something similar for tax rates, the difference from what I can see you're doing to what I'm doing, is that I call the API for the component list from outside, so I only get it once, and then assign that list into the component with a "list" attribute to work with. I then do the same as you to assign the selected status into the component. Seems to work.
  • gazinhio

    2 years ago

    Just out of interest, what's the app your building? Is it for a client or are you building a SaaS?
  • Victor Giron

    2 years ago

    @ I tried that approach as well but it has the same result, it's just passing the first item statusid to all the instances of the status component.

    I'm recreating an app for my client that I currently have in Weweb. I really want to migrate from Weweb to Toddle, it's a logistics internal app
  • gazinhio

    2 years ago

    OK, let me have a look and see if I'm doing something different with mine. If it's a bit longer of an explain, I'll do a Loom.
  • gazinhio

    2 years ago

    It's been a while so had to refresh myself, dunno if it's best way of doing it but I'll do a Loom and put the link here.
    🙌1
  • Lucas G

    2 years ago

    Would it be ok if I took a look at the project or the component? Hard to say but I’d start with the data going into into the repeated row and go from there
  • Victor Giron

    2 years ago

    Of course! You want me to show you the flow in detail or want me to invite you to the project?
  • Lucas G

    2 years ago

    You can just dm me the link
  • Victor Giron

    2 years ago

  • in the popover I added next to the labels the current id passing, as you'll see it's passing the first row status id
  • to every instance of the component
  • gazinhio

    2 years ago

    Would you be ok if I created a new branch and just tried something?
  • Lucas G

    2 years ago

    We can't create branches unless we're part of the project I don't think
  • I just opened it and the popovers seem broken to me
  • 1238168197597888615-image.png
  • Haven't looked around yet, that's just how it looks on load
  • Victor Giron

    2 years ago

    you can clone it
  • Lucas G

    2 years ago

    They seem to be piled up on the corner
  • gazinhio

    2 years ago

    It works in the app ok though. Just spotted a few things that might be causing it but wanna see if I can solve it before.
    🙌1
  • Victor Giron

    2 years ago

    Yeah I think is a rendering thing but when you work on it or preview it, would work normal
  • Lucas G

    2 years ago

    Ok just wanted ot make sure lol
    🙌1
  • gazinhio

    2 years ago

    I've cloned it, I'll see if what I think is wrong, actually is
    🔥1
  • Victor Giron

    2 years ago

    Thanks a lot guys!
  • Lucas G

    2 years ago

    @Victor Giron I believe the issue is that the popver doesn't have a unique ID
  • Or rather, it is the same popover on all the rows
  • gazinhio

    2 years ago

    Yeah I think it's calling the same popover element for each one which is hooked up to the first status id
  • Lucas G

    2 years ago

    One sec lol
  • gazinhio

    2 years ago

    I think you might have to set a random-number based id and assign it to the id attribute of each one.
  • Lucas G

    2 years ago

    But yeah, I cloned it and added an id and the numbers update
  • 1238179320153899100-image.png
  • 1238179417226739853-image.png
  • gazinhio

    2 years ago

    Yeah, Lucas has got it, I've got it working in terms of showing the right popover element target with the right status id, but now it's showing in the wrong place 😆 🤷‍♂️ @Lucas G is it showing in the right place for you eg anchored to the main button?
  • Lucas G

    2 years ago

    Yes
  • Both the popover and the function need the same ID
  • gazinhio

    2 years ago

    Ah yeah, the function
  • Lucas G

    2 years ago

    Speaking of which, I think I had a popover dropdown working without JS
  • Let me see if I can find it
  • Though I'd prefer to use the upcoming anchor updates
  • It worked though, let me see if I can find it
    🔥1
  • gazinhio

    2 years ago

    🤯 Spill!
  • Please 😉
  • Victor Giron

    2 years ago

    This is awesome! So I just need to add a variable with a random id and add it to the popover and the click event?
  • gazinhio

    2 years ago

    You could just have the "orderstatus" and add the itemid attribute, if you know that'll be unique. But prob a randon number is safer. Yeah, add it as the id attribute for the drop-down <div>, the popover target and the param for the coded action for positioning.
  • Victor Giron

    2 years ago

    It's working! Thanks so much guys! That was blocking me.
    I just need to find the way to hide the popover when user clicks on the button while the popover is visible haha
  • I think I have an idea for that
  • Victor Giron

    2 years ago

    also is it a better idea to have the apicall for the status list inside the component or in the page?
  • Tod

    2 years ago

    Great energy @Victor Giron! Your continuous contribution to the toddle Community just made you advance to Community Level 13!
  • gazinhio

    2 years ago

    Thanks for the anchor code, gonna have to chance my drop-downs now I reckon. Although Lucas reckons he's got a way without the JS
  • gazinhio

    2 years ago

    I'd deffo have it in the main page and pass it as a list, as it's calling it every time for every row at the moment.
  • gazinhio

    2 years ago

    When they switch to a lower limit on API requests, the less calls the better.
  • Lucas G

    2 years ago

    I am not sure if it works on non-chromium browsers**
  • gazinhio

    2 years ago

    If you've cracked this, you're a super-hero 😆
  • Just need to add it to the popover div and function
  • gazinhio

    2 years ago

    Works on Arc and Safari so far
  • Lucas G

    2 years ago

    My version works on two main things
  • The popover API docs specify inset: unset to allow positioning
  • But the popover api also uses an overlay and goes on the window's top-layer
  • So I'm using overlay: none
  • Though overlay is not fully supported yet
  • So positioning would need to be tweaked for it to work everywhere untill the css properties are fully supported
  • Lucas G

    2 years ago

    I think there is another way to do it to make it more compatible but it requires adding a wrapper to it
  • gazinhio

    2 years ago

    Nice. My CSS knowledge does that extend to even pretending to know what most of that means but I'm open to trying anything. 🤓 👍
  • Lucas G

    2 years ago

    lol I can try to wrap it to make it work better across browsers
    👍1
    💪1
  • gazinhio

    2 years ago

    @Victor Giron If it's of any interest, here's the clone that I did as well. I changed loads of other stuff first before I came to the right conclusion 😳 but it all works, didn't break it! https://editor.nordcraft.com/projects/logistics_clone_alksdfjklasejflkasjd/branches/start/components/dropdown-status?canvas-width=800&canvas-height=800
    🔥1
  • gazinhio

    2 years ago

    Sorry, I think I've just reposted Lucas' link! 😆
  • There you go!
  • Victor Giron

    2 years ago

    hahah got it! thank you @
    👍1
  • Updated so it works on well on Safari too
  • Lucas G

    2 years ago

    I think I'll update my dropdowns with this going forward
  • Once some css properties are fully supported then it'll be even simpler
  • Victor Giron

    2 years ago

    Question Lucas, does this relocate the popover to prevent to get out of the viewport when the target is close to the viewport boundaries?
  • Lucas G

    2 years ago

    I didn’t go that far
  • I only wanted to make a dropdown with the popover api
  • Since I’m using fixed values on it, it shouldn’t
  • Victor Giron

    2 years ago

    Got it, the js action I used makes that happen, changes the position to keep the popover inside
  • gazinhio

    2 years ago

    @Victor Giron @Lucas G Fellaz, big thanks for our convo re popovers yesterday. Just converted my main dropdown component to popovers using a lot of what we discussed, big thanks to the code shared by Victor. Took a bit more faffing around to get it to toggle on demand and a few code snippets but it's working great. V happy with it! 😊 If there's anything you'd like to me share about it just let me know. Have a good one guys!
  • Stockton

    2 years ago

    Are you gonna make a package of the popover? 👀
  • Victor Giron

    2 years ago

    Awesome!! Who would think popovers were so complex right? I’m happy with mine also, thanks a lot for the huge help
  • Lucas G

    2 years ago

    I just realized I never actually shared the dropdown popover component 😅
  • Pure CSS popover dropdown
  • gazinhio

    2 years ago

    Probably should actually, a bit app-specific at the mo, maybe make it a bit more generic and then do it.