Benoît Cerise
Benoît Cerise

Reputation: 652

Google App Maker not reocognising some of its own widgets

In Google App Maker, I have several widgets on a page. One of these widgets is called Label12 (shown in Screenshot 1). It definitely exists and is also shown in the breadcrumb trail at the top of my screen.

However, when I attempt to reference Label12 in my code, it does not seem to exist.

If I use the ctrl+space code completion helper, the Label12 widget is not shown as an option (shown in screenshot 2).

When I attempt to code it manually (e.g. app.pages.Reconciliation_Details.descendants.Label12.visible) it returns the error "Cannot set property 'visible' of undefined".

Why can App Maker not see Label12?

Screenshot 1 showing Label12 on page: Screenshot 1 showing Label12

Screenshot 2 showing absence of Label12 when coding: Screenshot 2 showing absence of 'Label12' when coding

Upvotes: 1

Views: 90

Answers (1)

Morfinismo
Morfinismo

Reputation: 5253

App Maker can see Label12. The point is that the label is inside a table widget, hence according to the documentation:

Because a table is a collection of other widgets, you can't use the Widget API to interact with a table. However, you can use scripts to manipulate the individual widgets that make up a table.

The above statement makes sense because the amount of rows a table will display depends on the datasource items; i.e., the rows are dynamically created when the widget datasource is loaded in the ui. Therefore, in order to access the label you need to first access the children of the Table1Body, which is a collection of named values known as PropertyMap.

I believe you are trying to hide/show that specific label based on some logic. The correct way of doing it would be something like this:

var rows = app.pages.Reconciliation_Details.descendants.Table1Body.children._values;
for(var i=0; i<rows.length; i++){
    var row = rows[i];
    var label = row.descendants.Label12;
    label.visible = true; // or false
}

Upvotes: 2

Related Questions