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]);
Solved! Go to Solution.
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);
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);
Yes! Much appreciated.