Calculation of variables does not show actual value immediately

  • ssssadsadasd

    13 days 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
  • Lucas G

    13 days 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

    13 days ago

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

    13 days 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?
  • Lucas G

    13 days ago

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

    13 days ago

    yeah, I understand
  • Lucas G

    13 days ago

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

    13 days 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

    13 days ago

    got it. thanks
  • Lucas G

    13 days ago

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

    13 days 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?
  • Lucas G

    13 days ago

    Because formulas can be calculated server-side
    πŸ‘2
  • Lucas G

    13 days ago

    It's also a recommended best practice to use formulas whenever possible instead of variables
  • Lucas G

    13 days 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

    13 days ago

    @Lucas G great info thanks.
    ok will find and check the video
  • Lucas G

    13 days ago

    πŸ‘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.