How to keep user's preferences

  • benjabievres-1309122333214113873

    benjabievres

    4 months ago

    Hello!

    I created a "checkbox" Input and a corresponding "showViewed" variable => I will use the variable in a Filter to show only specific items.
    This part is fine, even if the formulas are a little more tricky since we have to use the "checked" attribute and not the value that is passed by the event.

    But, I would like to keep the user preferences so that it goes back next time the user opens the page. For this, I suppose that Local Storage is the way to go.

    I tried different things, but I can't make it work properly (in 'preview' mode).

    So, how can this be achieved? (let's call the Local Storage variable "showViewedLocal".
    - The first time the user opens the web app in a browser, "showViewedLocal" doesn't exist.
    - When should I load "showViewedLocal"? on the onLoad event? And shall I store this variable to "showViewed"
    - When should I store "showViewedLocal"? on each "change" event of my checkbox?

    If you know any tutorial I could use to learn, it would be great!

    Thanks

    Benjamin
  • tomthebigtree-1309126460493008926

    Tom Ireland

    4 months ago

    You probably want a switch for the on load event. Use a formula to get the value from local storage and use that, else the user is new so can choose the option to change it. On the next load, it should get the value from local storage successfully.

    I did something like this with session storage for a simple todo app. Can share the branch URL if you want to poke around.
  • tomthebigtree-1309126931366547466

    Tom Ireland

    4 months ago

    This is all assuming the browser is not set up to clear data when closing as that could have an effect on that. For consistency, it’s better using a database but then you need auth and stuff for user preferences, etc.
  • benjabievres-1309142173618540565

    benjabievres

    4 months ago

    Thanks (again) Tom!! I will give it a try. And I will let you know if I need access to the branch you built. 😎
  • benjabievres-1309151385563955240

    benjabievres

    4 months ago

    @Tom Ireland it works now! I was trying to use also a classic variable to map its value to the "checked" attribute of my checkbox, but now I realize I don't need this variable since I can just use the Local Storage variable πŸ˜…
  • Thanks again!
  • tomthebigtree-1309151899307606067

    Tom Ireland

    4 months ago

    πŸ™Œ Nice one! Glad to hear you got it working. πŸ’ͺ
    πŸ’œ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.