Open widget from scalebar widget

375
2
Jump to solution
05-11-2018 08:59 AM
JamesCrandall
MVP Frequent Contributor

Theme: Launchpad

WabDev 2.7

I'm trying to implement what is found in THIS thread.  I need to open a widget from the ScaleBar widget when the app loads.  However, the var abc is getting set to undefined and not sure why.

var widgetsConfig = this.appConfig.widgetPool.widgets;
            var widgetId;
            for (var i in widgetsConfig) {
                if (widgetsConfig[i].name == "My Widget Name") {
                    widgetId = widgetsConfig[i].id;
                    break;
                }
            }
            var abc = WidgetManager.getInstance().getWidgetsByName("AnchorBarController")[0]; //abc is getting set to undefined
            debugger;
            abc.setOpenedIds([widgetId]);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

James the issue is a timing issue. The Scalebar widget is initiated before the Anchorbar Controller is created. You can use a setTimeout or move the code from the Scalebar widget to somewhere else where you are sure the Anchorbar Controller is already created. I just used a timeout and it worked fine:

        var widgetsConfig = this.appConfig.widgetPool.widgets;
        var widgetId;
        for(var i in widgetsConfig) {
          if(widgetsConfig[i].name == "InfoSummary") {
            widgetId = widgetsConfig[i].id;
            break;
          }
        }
        setTimeout(function(){
          var abc = WidgetManager.getInstance().getWidgetsByName("AnchorBarController")[0]; //abc is getting set to undefined
          debugger;
          abc.setOpenedIds([widgetId]);
        }, 1000);

View solution in original post

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

James the issue is a timing issue. The Scalebar widget is initiated before the Anchorbar Controller is created. You can use a setTimeout or move the code from the Scalebar widget to somewhere else where you are sure the Anchorbar Controller is already created. I just used a timeout and it worked fine:

        var widgetsConfig = this.appConfig.widgetPool.widgets;
        var widgetId;
        for(var i in widgetsConfig) {
          if(widgetsConfig[i].name == "InfoSummary") {
            widgetId = widgetsConfig[i].id;
            break;
          }
        }
        setTimeout(function(){
          var abc = WidgetManager.getInstance().getWidgetsByName("AnchorBarController")[0]; //abc is getting set to undefined
          debugger;
          abc.setOpenedIds([widgetId]);
        }, 1000);
0 Kudos
JamesCrandall
MVP Frequent Contributor

Yes!  Much appreciated.

0 Kudos