Search code examples
widgetgoogle-app-maker

Appmaker: Handle several copies of a page fragment as one?


I have a SideMenu page fragment in my app. On each and every page, I have a copy of this page fragment.

My intention was to create a SideMenu with openable SubMenus (only one sub menu could be open at a time), but I could not get it done to make the app "remember" the state of the SideMenu( like which SubMenu should be open, and which ones shouldn't), because on each site there is a different widget, so when in my code ( in my onClick events) I refer to the widget, I am not handling "a global SideMenu" but rather a specific copy of it, unique to that page.

Sadly, this took several hours of debugging to realize, I am defeated.

Is there anyway to place a page fragment on a page, so I can handle that widget on its own, not just it's copies?

Thanks in advance, I can try to specify more the question if it's needed.


Solution

  • I agree with @MarkusMalessa. You need to invoke the widget on every page and then apply whatever change on it. I am doing the samething on a project in which I intend to shrink and expand the sideMenu. To give you an idea, evertime I click a button on the side menu responsible for the logic, this is the code that's invoked:

    var pages = app.pages._values;
    pages.forEach(function(page){
      var sideMenu = page.descendants.sideMenu1;
      if(sideMenu){
        if(widget.text === "chevron_right"){
          sideMenu.getElement().style.width = "300px";
        } else {
          sideMenu.getElement().style.width = "60px";
        }
      }
    });
    

    That way every sideMenu widget inside each page that has it receive the same changes.