Search code examples
google-app-makermodalpopup

How to make pop-up data reflect selected record?


The case:

I have Activities as datamodel.

I have set Activities to have many-to-many relationship with themselves to represent a Parent / Child relationship.

I have set up an accordion widget. Each row of the accordion contain basic data about the Activity record + some buttons.

I have set one of the button's onClick functions to open a popup, which allows me to edit the Activity detail in a form.

When I click a different record from the same accordion, the form from the popup reflects the data in the selected record.


The problem:

I have nested accordions which represent the "Child" Activities of the Parent Activity.

I have also added a similar button, which opens a popup. I can open the popup, which targets the child records, but cannot make it open the specific record, from which I pressed the button.

So the popup open by default on the first child.

Please help - how can I make the popup change naturally to reflect the datasource / selected record of even nested datasources?


What I tried:

In order to try and make to popup work I have tried to set the datasource based on the relationship:

Activities: Sub_Activities(relation)

This works to the extent of showing the related items, but popup content does not dynamically change on clicking a different child record or clicking the button from a different child record.

In both cases what is shown is the first child record.


Solution

  • What I understand is that you have a set up in which you click a button and a popup shows. The popup should let you view/edit the record referenced in the row where the button is. If that is the case, then probably you already have almost everything setup for the next thing to work. First, add a string custom property to the popup and name it selectedKey. Then, on the onClick event of the button that opens the popup, add something like this:

    var key = widget.datasource.item._key;
    app.popups.MYPOPUP.properties.selectedKey = key;
    app.popups.MYPOPUP.visible = true;
    

    Now, go to the popup content and add the following on the onAttach event handler:

    var key = widget.root.properties.selectedKey;
    widget.datasource.selectKey(key);
    

    This is the general idea of how to make it work; However, in order for it to work, your datsources in the widgets should be properly set up. Good luck!