I'm trying to open the Print widget from another widget. If the widget has already been loaded I have no problem. If the print widget hasn't been loaded, it creates the widget and it creates the panel, but nothing shows. How do I show the panel?
Console:
widget [widgets/Print/Widget] created.
PanelManager.js:83 panel [widgets_Print_Widget_35_panel] created.
Code:
_openPrintWidget: function () {
if (this.wManager) {
var widgetCfg = this._getWidgetConfig('Print');
if(widgetCfg){
var printWidget = this.wManager.getWidgetByLabel(widgetCfg.label);
if(printWidget){
this.wManager.openWidget(printWidget);
this.pManager.showPanel(printWidget);
} else {
this.wManager.loadWidget(widgetCfg).then(lang.hitch(this, function(widget){
if(widget){
this.wManager.openWidget(widget);
this.pManager.showPanel(widgetCfg);
}
}));
}
}
}
},
Solved! Go to Solution.
Robert,
That worked beautifully! The widget opens just the way it should. Is there an easy way to get a reference to the widget using the widgetid defined in this code?
Tom
Sure, just use
var printWidget = this.wManager.getWidgetById(widgetId);
Robert,
Close but still not quite there.
//This works great and opens the print widget
var abc = WidgetManager.getInstance().getWidgetsByName("AnchorBarController")[0];
abc.setOpenedIds([widgetId]);
//None of the 3 sets a reference to the printwidget
//Error - printWidget = undefined, widgetId = "widgets_Print_Widget_35"
//printWidget = this.wManager.getWidgetById(widgetId);
//Error - didn't work at all
//printWidget = WidgetManager.getWidgetById(widgetId);
//Error - printWidget = undefined
printWidget = this.wManager.getWidgetById("widgets_Print_Widget_35");
It opens up the print widget fine, but in each case it just says the printWidget is undefined.
Tom,
you have to wait for the widget to open.
var widgetsConfig = this.appConfig.widgetPool.widgets; var widgetId; for(var i in widgetsConfig){ if(widgetsConfig.name == "Print"){ widgetId = widgetsConfig.id; break; } } var abc = WidgetManager.getInstance().getWidgetsByName("AnchorBarController")[0]; abc.setOpenedIds([widgetId]); var printWidget; setTimeout(function(){ printWidget = WidgetManager.getInstance().getWidgetById(widgetId); console.info(printWidget); }, 1000);
Robert - That worked. I did need to add a callback, but now it works well. Thanks so much for your help!!
This was the calling function:
onTest: function () {
var self = this;
self._openPrintWidget(function() {
this.PrintWidget.testPrint();
});
},
This was the final _openPrintWidget function:
_openPrintWidget: function (callback) {
//Opens print widget and assigns it to global variable PrintWidget
var printWidget;
var widgetCfg;
if (this.wManager) {
var widgetCfg = this._getWidgetConfig('Print');
if(widgetCfg){
printWidget = this.wManager.getWidgetByLabel(widgetCfg.label);
if(printWidget){
this.wManager.openWidget(printWidget);
this.pManager.showPanel(printWidget);
this.PrintWidget = printWidget;
callback();
} else {
//alert("code2");
var widgetsConfig = this.appConfig.widgetPool.widgets;
var widgetId;
for(var i in widgetsConfig){
if(widgetsConfig.name == "Print"){
widgetId = widgetsConfig.id;
break;
}
}
var abc = WidgetManager.getInstance().getWidgetsByName("AnchorBarController")[0];
abc.setOpenedIds([widgetId]);
setTimeout(function(){
printWidget = WidgetManager.getInstance().getWidgetById(widgetId);
console.info("PrintWidget: " + printWidget);
this.PrintWidget = printWidget;
callback();
},3000);
}
}
}
},
I'm getting "abc = undefined" when I run this and will not open the desired widget.
James,
You are going to have to be way more specific. Are you using the Launchpad theme that this thread is talking about?
Sorry -- yes, Launchpad theme, WAB Dev 2.7
Also, I started a new thread so as to provide points for answers! https://community.esri.com/thread/214625-open-widget-from-scalebar-widget
Hi Robert,
var abc = WidgetManager.getInstance().getWidgetsByName("AnchorBarController")[0];
The AnchorBarController in the above statement refers to what ?
I am not getting what controller need to be kept their ? and the AnchorBarController is not working for me.