Adjusting App Config for a widget inside Widget's WAB config menu

3381
5
12-16-2015 05:55 AM
AustinLasher
New Contributor II

I'd like to add a configuration option for the "preloadOnStart" setting in my application's settings menu for the Web AppBuilder. The problem is that this settings option is contained in the appConfig (root/config.json), inside the widget's object in the widget pool. I've only been able to adjust the widget's normal config (root/widgets/MyWidget/config.json) using the examples I've found online. I'd also like to set other properties, like the widget id, inside this config file somewhere.

I just don't want my user to have to go into the file and type that in manually, I'd like for the system to take care of it somewhere for them. How does the WAB create the app config file, and how could I create a configuration option for appConfig items like this? Thanks, I appreciate any input.

Austin

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Austin,

   In a widget you have access to the main config by using this.appConfig

example:

this.appConfig.widgetOnScreen.widgets[4]

AustinLasher
New Contributor II

Hi Robert,

Thanks for your reply, that does help.

To my understanding, though, the config object that specifies the widget I'm configuring may change locations depending on where the user puts it (say, in a controller versus not in one.) That means I'd have to search the appConfig for the correct object. I can do that, but that brings up another problem: what if my user has to widgets with the same name? If I searched for it by "name" I could potentially be configuring the wrong app's config. Is there a better way than this?

Thanks a lot,

Austin

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Austin,

   I would search by the widgets id and not the name to avoid this situation. In the widgets code you can get the widgets id by using "this.id;"

0 Kudos
AustinLasher
New Contributor II

Hey Robert, thanks for all your help.

I did think of that. The problem, though, is that I need to set the id in the appConfig in the first place. I can't find it by id if I don't know what id it's set to before I use it. Is there a way of knowing what id the builder gives the widget before I change it?

Let me know, thanks again for your help!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Austin,

  Ok I was not thinking about you not running this code in the same widget you wanted the id for. The widgetManager class has several methods for getting widgets (by Id, by Label, by name).

https://developers.arcgis.com/web-appbuilder/api-reference/widgetmanager.htm

0 Kudos