PricingDocsAcademy
Bluesky ...
Wed, Dec 11, 11:17 PM

Best practice to build a survey

  • Lucvs

    1 month ago

    Hey guys,

    If you were to build a survey in toddle, with a lot of questions, conditional logic, and answers being saved in local/session storage which approach would you use and why?

    A) One page, with each question in separate divs, hide the div of every question whenever user goes to next question

    B) A lot of pages, separate page for each question, when a question is answered user gets redirected to next page
  • needtheanswers

    1 month ago

    I would use A) because I think that using 1 page for 1 question would get a little bit messy + you would have to run a request on each page (that is if you are using a db). Also I would definitely use components for that and repeat the component on 1 page based on the list of questions.
  • Tod

    1 month ago

    Great energy @needtheanswers! Your continuous contribution to the toddle Community just made you advance to Community Level 9!
  • Lucas G

    1 month ago

    I built a typeform clone a while back and my approach was to have question and answer components which changed with an array of questions
  • Each answer was saved to the array so user could navigate back and forth and update answers if needed
  • Lucas G

    1 month ago

    Something similar could be done and you can save the array after every answer, both locally or to your db
  • Lucas G

    1 month ago

    It was all on a single page and no components were repeated. It was all tracked and updated through the array
  • Worked pretty well and didn’t end up with a mess of divs/repeats
  • Lucvs

    1 month ago

    So you ended up having a component for each question / step in the survey?
  • Lucas G

    1 month ago

    No. A question and an answer component
  • The components were updated based on the index (question) in the array
  • Lucvs

    1 month ago

    Ahh I understand
  • Lucas G

    1 month ago

    In my case, it was multiple choice questions
  • Each with different values
  • By values I mean like a 'score' type of thing
  • Lucvs

    1 month ago

    It sounds like a pretty good approach actually
  • But, if there's conditional logic / calculations in some of the steps, it sounds like I'd have to break up the components
  • Or in essence, one array for each string of questions till page of calculation or whatever it may be
  • Lucas G

    1 month ago

    It depends
  • Lucas G

    1 month ago

    The logic could be built into the array in some way or you could build the logic that if question 7 has answer 3 then go into this new array, etc
  • The components would stay the same
  • The formulas could dictate what shows
  • Lucvs

    1 month ago

    Yeah I see, it probably is a pretty flexible approach
  • I guess I could also use style variables to change the styles within each component based on what is shown in a given array right?
  • Lucas G

    1 month ago

    Yup, a lot of flexibility with that approach
  • And toddle makes it easy to build all the logic
  • Lucas G

    1 month ago

    You could also use classes
  • That only show on certain conditions
  • Might be easier
  • Lucvs

    1 month ago

    Thanks for your help, will try and see how I can set this up for my project

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.