1

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.

  • On some occasions I have run into this problem if the relation is not prefetched in the main datasource. If you have not already, I would suggest prefetching Sub_Activities in your Activities datasource. As far as your setup goes, do you have two popups or only one popup that is supposed to handle editing for both Activities as well as Subactivities? – Markus Malessa Aug 27 '19 at 14:58
  • @MarkusMalessa 1: I have added a Prefetch - It does not seem to change the outcome. 2: I have 2 different popups in this case. Popup1 addressing the button from Parent Activity (which works fine). And Popup2 which is based on Activities: Sub_Activities(relation). Popup2 - opens related records but is stuck on the default first entry and does not change data on clicking the button from another entry. Thank you for the time so far, I would appreciate any continued help! – Veso Yanchev Aug 27 '19 at 16:28
  • 1
    Pass the record key to the popup and on the `onAttach` event handler of the popup content use `widget.root.datasource.selectKey(recordKey);` – Morfinismo Aug 28 '19 at 01:05
  • @Morfinismo - I added the on Attach event, but I receive the following error, which I am not sure how to handle: Cannot read property 'selectKey' of null. Some more info: I added the onAttach to the popup which has datasource: Activities and a panel over it which has Activities: Sub_Activities (relation). I am sure this is a step in the right direction, I'm just not sure how to properly implement it. – Veso Yanchev Aug 28 '19 at 06:43

1 Answers1

2

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!

Morfinismo
  • 4,985
  • 4
  • 19
  • 36
  • you are a GOD! Everything is working as intended! I am most thankful! Is there any way I can further commend you for your assistance here at stackoverflow? I'm new and still getting the hang of this community. – Veso Yanchev Aug 28 '19 at 14:34
  • @VesoYanchev Thanks men. Its really too much to say that I'm GOD. I'm just an appmaker expert who happens to love helping others when possible. Glad the solution worked out for you. You can always upvotes answers apart from accepting them when you find a solution or question that suits you. Cheers! – Morfinismo Aug 28 '19 at 15:12