Calculation of variables does not show actual value immediately

  • ssssadsadasd-1324085915026587771

    ssssadsadasd

    3 months ago

    I have a reusable.
    The reusable has an attribute item = { "created_at": "2025-01-01T17:56:04.15182+00:00"}
    The reusable has a variable milliseconds = now - item.created_at (which translates in milliseconds). I use this variable because I do not want to calculate it for each if condition.
    The reusable has a text which translates to different time format: so if created_at is less than one minute = just now, less than 1 hour = x minutes etc.

    Suppose created_at is less than one hour. It should show immediately xm(inutes) but it first shows the last item of the if condition and then correctly shows xm(inutes). [see video](https://vimeo.com/1043286016/a2cc66cd60?ts=0&share=copy)

    why does this happen? here is the [test url](https://toddle.dev/projects/turquoise_o_en_lars_permanent_chicken/branches/start/components/test?leftpanel=design&canvas-width=800&canvas-height=800&rightpanel=attributes).

    P.S.: make sure to change the value in the page to a date less than 1 hour prior
    βœ…1
  • lucasg-1324087566395248650

    Lucas G

    3 months ago

    Your video seems like the browser is being sluggish. Not sure if this is a local issue more than a toddle issue
  • It doesn't behave like that on my end
  • needtheanswers-1324088070248599592

    needtheanswers

    3 months ago

    Did you try using a formula instead? Formulas should update instantly
    πŸ‘1
  • ssssadsadasd-1324088095636848641

    ssssadsadasd

    3 months ago

    @Lucas G is it supposed to behave like that anyway? so if the first condition is true, then why does it show the value of the last condition which it is not supposed to achieve?
  • lucasg-1324088302814367765

    Lucas G

    3 months ago

    It's not about the formula itself. The variable is not being set right away
    πŸ‘1
  • ssssadsadasd-1324088567214899220

    ssssadsadasd

    3 months ago

    yeah, I understand
  • lucasg-1324088694847836303

    Lucas G

    3 months ago

    Basically the variable isn't set so the formula runs through, then the variable sets and it updates.
  • ssssadsadasd-1324088708097642557

    ssssadsadasd

    3 months ago

    yeah, that seems the best solution, but I would like to keep this as much toddle native as possible as i am not a coder
  • ssssadsadasd-1324088754876584056

    ssssadsadasd

    3 months ago

    got it. thanks
  • lucasg-1324088837386928150

    Lucas G

    3 months ago

    He's not saying use code
  • Code runs client-side so it's more likely to flash text before updating
  • ssssadsadasd-1324089270289301565

    ssssadsadasd

    3 months ago

    ah ok so the formulas in the right sidebar. why is that supposed to solve the issue since I have to just copy-paste the same thing?
  • lucasg-1324089747731251284

    Lucas G

    3 months ago

    Because formulas can be calculated server-side
    πŸ‘2
  • lucasg-1324090362880327690

    Lucas G

    3 months ago

    It's also a recommended best practice to use formulas whenever possible instead of variables
  • lucasg-1324090639951986758

    Lucas G

    3 months ago

    Or rather, better said, if the value can be calculated via formulas, it's better to do that than to use variables
  • Variables are more for data that is mutable. Data that you're manipulating and using to update UI, etc
  • I recommend that video Andreas made on the subject over on the toddle channel
  • ssssadsadasd-1324091187451269252

    ssssadsadasd

    3 months ago

    @Lucas G great info thanks.
    ok will find and check the video
  • πŸ‘1

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code β€” but accessible to your entire team!

Try toddle β€” it's free!

Β© Copyright 2024 toddle. All rights reserved.