PricingBlog

Dynamic survey, how to save user responses issue

  • yoelfdz-1211272566489092169

    yoelfdz

    1 year ago

    Hello community,

    I've developed a survey that dynamically adapts based on a JSON configuration. I've included a video showcasing the survey.

    Essentially, the survey comprises elements consisting of questions with various types of answer formats, such as boolean, textarea, checkboxes, and toggles. When I say "dynamic," I mean that the number of categories, questions, and response formats are determined by the JSON configuration (also attached).

    My issue is that I need to save the responses of the user somehow, I was trying to save the responses updating the "response" object on the same JSON using the set formula but I can't make it work, do not know why.
    Another option could be creating a new array variable and appending on click the response of each option_id, but to be honest I'm a bit stuck here.

    Would be helpful to know how you would do this, thanks beforehand 😄
  • yoelfdz-1211281902871380029

    yoelfdz

    1 year ago

    here for example I can save on a separate variable the status of a toggle option. Would like to update my main JSON variable with that new ("response": true) status, just that status
    1211281902623924224-Captura_de_pantalla_2024-02-25_a_las_12.58.33.png
  • lucasg-1211348020193534022

    Lucas G

    1 year ago

    If you want to save responses to your existing array then you would not use append
  • In the example you shared, remove the append node and specify the path in the set node
  • I think you’d use an array node with the items:
    Item Index
    response
  • Let me know if that makes sense
  • yoelfdz-1211348848769892473

    yoelfdz

    1 year ago

    Correct, trying to modify the "response" value on click, I think I'm on the right direction here but honestly do not know how to filter index of the item (using repeated items)
    1211348848581017620-Captura_de_pantalla_2024-02-25_a_las_17.26.08.png
  • yoelfdz-1211349113212379166

    yoelfdz

    1 year ago

    I'm stuck on getting the path for the find index node
  • lucasg-1211350972392280105

    Lucas G

    1 year ago

    1211350972165656576-image.png
  • Use the repeating item's Index value instead of Item
  • yoelfdz-1211354026210492436

    yoelfdz

    1 year ago

    Oh wow, can I navigate through the JSON like this? Is this what you mean?
    1211354026017558579-Captura_de_pantalla_2024-02-25_a_las_17.48.02.png
  • lucasg-1211354495779344539

    Lucas G

    1 year ago

    Use it to set only the one value you need to update
  • The path array just specifies which item you are targeting
  • lucasg-1211354870225969243

    Lucas G

    1 year ago

    In the example you showed, it would mean that there item you are updating is 6 levels deep in that first index's object
  • Does that make sense? lol
  • lucasg-1211355208697913385

    Lucas G

    1 year ago

    Wait, I misread your comment. Simple answer is, yes, you can use arrays to navigate paths
  • yoelfdz-1211355921754751047

    yoelfdz

    1 year ago

    These are the objects I want to update, if I understood correctly, it should be ok like this, isn't it? Appreciate the help Lucas, I've since yesterday struggling with this 😅
    1211355921846894702-image.png
  • lucasg-1211356405433503794

    Lucas G

    1 year ago

    The first index would be correct but not the other 2
  • The values wouldn't always match up
  • lucasg-1211357292814016542

    Lucas G

    1 year ago

    If your main array is complex/has a lot of levels, it might just be easier to create a separate answers array
  • That way you don't have to worry about finding the proper index of the nested items, etc
  • lucasg-1211358283261022228

    Lucas G

    1 year ago

    In this example, there's a nested 'options' array which would have its own index so the repeating index wouldn't work here. The repeating index refers to the main array that is being repeated over
  • lucasg-1211358649797181490

    Lucas G

    1 year ago

    It is possible to do but it would be a big formula
  • yoelfdz-1211359906561523763

    yoelfdz

    1 year ago

    Ok, will continue looking into this now that I know how to navigate paths, thanks Lucas. Will update here the progress
  • yoelfdz-1211438188225101914

    yoelfdz

    1 year ago

    For anyone interested, I managed to do it like this. (This is only for boolean type options)
    1211438187982094366-image.png
  • yoelfdz-1211438473978974248

    yoelfdz

    1 year ago

    Do not know why the Array says Null, it's not null, the string written are the same as the previous picture
  • yoelfdz-1211438739079958588

    yoelfdz

    1 year ago

    And it's on the main JSON file shared above as I intended