Select to view content in your preferred language

How to open a widget (in a placeholder) programmatically ?

5388
14
Jump to solution
10-22-2015 02:07 AM
MathieuVILLEMONT1
Deactivated User

In the Web Appbuilder Developer Edition, say I want to open a widget which is not in a controller but in a place holder. How can I manage that ?

I've tried using the WidgetManager openWidget(widget) followed by PanelManager showPanel() functions but it only works if the widget has already been opened once before (manually).

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Mathieu,

  I have no problem at all opening a widget in a onscreen placeholder that has not been opened yet using these two lines of code only from inside another widget.

var pm = PanelManager.getInstance();
pm.showPanel(this.appConfig.widgetOnScreen.widgets[4]);

View solution in original post

14 Replies
RobertScheitlin__GISP
MVP Emeritus

Mathieu,

  I have no problem at all opening a widget in a onscreen placeholder that has not been opened yet using these two lines of code only from inside another widget.

var pm = PanelManager.getInstance();
pm.showPanel(this.appConfig.widgetOnScreen.widgets[4]);
LefterisKoumis
Frequent Contributor

Robert,

for on screen widget that is not visible and not started, I tried this but it does not open the widget

var wm =WidgetManager.getInstance();

wm.openWidget("widgets_BufferSelection_53");

The widgets_BufferSelection_53 is the widget id as identified in the config.json

Thanks.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   Did you try that code that is marker as the answer?

0 Kudos
LefterisKoumis
Frequent Contributor

Yes, I did. It never open the widget.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   I just tried these two lines of code again and they worked flawlessly:

var pm = PanelManager.getInstance();

        pm.showPanel(this.appConfig.widgetOnScreen.widgets[4]);

LefterisKoumis
Frequent Contributor

Hmm. I am wondering what do I do wrong.

config.json:

"widgetOnScreen": {

    "widgets": [

      {

        "uri": "widgets/BufferSelection/Widget",

        "version": "1.3",

        "id": "widgets_BufferSelection_53",

        "name": "BufferSelection",

        "label": "Buffer Selection",

        "openAtStart": false

      },

.............

widget.js of another widget that calls the Buffer Selection

.........

var pm = PanelManager.getInstance();

pm.showPanel(this.appConfig.widgetOnScreen.widgets["widgets_BufferSelection_53"]); 

........

and I get the error:

Cannot read property 'id' of undefined for the second line above

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   Because the pm.showPanel function is expecting the the whole widget configuration object and this.appConfig.widgetOnScreen.widgets["widgets_BufferSelection_53"] is not doing that. what is the index (i.e. postilion number) of the widgets_BufferSelection_53 in the widgetOnScreen widget array?

Once you figure that out then use that number as below:

pm.showPanel(this.appConfig.widgetOnScreen.widgets[0]);

0 Kudos
LefterisKoumis
Frequent Contributor

A childish mistake. I assumed that the parameter in the this.appConfig.widgetOnScreen.widgets is the widget id and I didn't notice the array.

Yes, it works now. However, when the Buffer Selection widget opens it closes the widget that calls it. How can I retain both widgets visible?

Thank you.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   Depends on the theme you are using. Most themes are only permited to have on widget open at a time. But the Launchpad theme allows for multiple to be open and you can have a on screen and a widget in the side panel of the foldable theme open at the same time.

0 Kudos