How to add a new element as child of an already selected element

Hi there!

  • I have “Tier 1 blocks” and “Tier 2 blocks”.
  • Tier 2 blocks are children of Tier 1 blocks
  • When I click on a Tier 1 block, my app successfully displays it’s children of Tier 2 blocks, in a new repeating group.
  • I want to create an ‘add Tier 2 block’ button which ‘knows’ to add it as a child of the already/previously selected Tier 1 block but I’m not sure how to do this. I tried playing around with states but I couldn’t work out how to reference the ‘already selected block’.

This diagram hopefully helps to articulate my problem :

Any help very welcome!

Are the items in tier 1 a data type and the items of tier 2 are a list of things attached to the selected item in the tier 1 block? If that is the case then when you click the add tier 2 block button you just need to create a thing (one of the items that is in the list of things attached to the selected item in the tier 1 block) and then make changes to the selected item in tier 1 block by adding the result of the previous step to its’ list of things.

If the tier2 references the selected item then you should be able to reference it in the same way in the workflows.

yes that’s right - but how do you ‘reference the selected item’ that’s what I’m struggling with. Do you achieve this via states? Setting a state when I tap any of the Tier 1 block buttons?

Yes that is exactly it. Set a state on the page called selectedTierOne that is the same data type and every time one of those blocks in the tier 1 is clicked make that thing the selectedTierOne. Then Tier 2’s data source will be selectedTierOne’s list of things.

This topic was automatically closed after 70 days. New replies are no longer allowed.