Search code examples
google-app-maker

Google App Maker: How to assign id to HTML widget based on datasource?


I have a popup that is shown when a user clicks on the item of a list. Once the pop up shows, there is an HTML widget within it, in which I'd like to give it an 'id' like:

<div id="builder-<idOfItemSelectedHere>"></div>

How can I do this in Google app maker?


Solution

  • The following would be a possible solution. For you listrow onclick event enter the following:

    var htmlwidget = widget.root.descendants.YourHTMLWidget;
    var item = widget.datasource.item;
    
    htmlwidget.html = "<div id='builder-" + item.id + "'>" + item.id + "</div>";
    

    You would want to remove your predefined html from your HTML widget however.