Is there an easier way to use a formula to set a value on a nested object in a variable?

  • /attachments/1325228860832354371/1325228861142863992/image.png

    KillerK009

    9 days ago

    I'm creating a basic workout plan builder which allows you to define any number of days and each of those days has any number of exercises. I have a program variable defined in Toddle and inside that there is a days object with a name and array of exercises[].

    Each exercise object has a name as well.

    I've attached a photo of the initial value of my program variable to show an example of the structure.

    I'd like the user to be able to edit the exercise name on any given day and so I have an inline-value-edit element from the starter-pack package and on the setEditedInput event I have a formula where I try to update the program variable by setting the name on a given exercise for a given day (based on the indices provided by repeat variables and input field the user selected), is there a way to simplify this formula?

    I'm used to coding where I could easily just do something like program.days[parentIndex].exercises[index].name = value in one line, but it seems like in Toddle I have to create a large formula for what seems like a simple operation, but perhaps I'm missing something.

    Is there an easier way to specify the Path value on that right-most Set to just provide the day and exercise indices to set the name and return the updated program as the output?

    Or is it typically easier in Toddle to limit how nested your objects get where instead of having a program object I'd just surface all the nested elements as separate variables and have a days variable instead?
    image.png
    image.png
  • /attachments/1325228860832354371/1325234860008280114/image.png

    KillerK009

    9 days ago

    I think I figured it out actually! Just needed to set that Path on the rightmost Set as an Array with all the info needed.
    image.png

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.