ArcGIS won't instantiate widgets sometimes

5555
7
12-02-2015 10:43 AM
tylerjones1
New Contributor

When creating and loading up my ArcGIS widgets using the ArcGis Javascript api, I am repeatedly receiving these errors:

dojo/parser::parse() error TypeError: Cannot read property 'toString' of undefined(…)

Uncaught Error: gis.dijit.Measurement: parser returned unfilled promise (probably waiting for module auto-load), unsupported by _WidgetsInTemplateMixin.   Must pre-load all supporting widgets before instantiation.

It seems that while trying to asynchronously load up all my widgets and dependencies..there is some sort of race condition that blows up the process and the widget simply won't work.

I have scoured the web to no avail and am now banging my head against the wall repeatedly. Any info or help on this would be greatly appreciated.

Regards,

Tyler

0 Kudos
7 Replies
thejuskambi
Occasional Contributor III

Could you share your code?

I had faced similar error, but different message. the measurement widget js was not loading properly. I was loading the widgets within a custom widget in my case. To fix it, I included the measurement widget in the require present in the html page. this ensured that the required js are retrieved before it loads my custom widget. May be you could also do something similar.

Hope this was helpful.

Thejus

0 Kudos
tylerjones1
New Contributor

I will try this. I put in a wait timer to delay 300 ms and it seems to make the problem happen much less frequently, but maybe if I load the required js way before i load the widget it will go away.

0 Kudos
MichaelLev
Occasional Contributor III

Dear thejus kambi,

I'm facing same problem.

I added some custom widget in the widgets-panel and have the same error.

Perhaps because my widget use API 4.16, maybe not all needed classes are loaded in time??

You wrote "To fix it, I included the measurement widget in the require present in the html page. this ensured that the required js are retrieved before it loads my custom widget.".

Please explain since I don't understand what to do - which is this html page and what exactly to write there.

Thanks,

Michael

0 Kudos
TyroneBiggums
Occasional Contributor III

Has the map loaded first? You might have to set up a initialization process that waits on things to load in a certain order.

KellyHutchins
Esri Frequent Contributor

Can you post code that shows the problem? You should not have to use timeouts to make the widgets work correctly. If you post your code we can probably help you figure out what's going wrong.

0 Kudos
tylerjones1
New Contributor

I am looping through an instantiating all necessary widgets with this code:

setTimeout(function () {

         this[widgetConfig.id] = new WidgetClass(options, put('div')).placeAt(pnl.containerNode);

     }, 500);

With this timeout in place, I rarely get the conflict. But without it my measurements widget then my custom export followed by my statistics widgets blow up and in that order.

I have only posted the define statements, because that it as far as each module gets. They do not reach post create when they blow up.

First I have a Controller module that handles all init, which is itself initalized with this:

define([

    "esri/symbols/SimpleFillSymbol",

    "esri/graphic",

    "esri/layers/GraphicsLayer",

    "dojo/Deferred",

     "dijit/registry", "dojo/query",

    'gis/dijit/AOSSplash',

  'esri/map',

  'dojo/dom',

  'dojo/dom-style',

  'dojo/dom-geometry',

  'dojo/dom-class',

  'dojo/on',

  'dojo/_base/array',

  'dijit/layout/BorderContainer',

  'dijit/layout/ContentPane',

  'gis/dijit/FloatingTitlePane',

  'dojo/_base/lang',

  'dojo/text!./templates/mapOverlay.html',

  'gis/dijit/FloatingWidgetDialog',

  'put-selector',

  'dojo/aspect',

  'dojo/has',

  'dojo/topic',

  'esri/dijit/PopupMobile',

  'dijit/Menu',

    'js/gis/plugins/offline-tiles-basic-min.js'

], function ( SimpleFillSymbol, Graphic, GraphicsLayer, Deferred,registry, query, Splash, Map, dom, domStyle, domGeom, domClass, on, array, BorderContainer, ContentPane, FloatingTitlePane, lang, mapOverlay, FloatingWidgetDialog, put, aspect, has, topic, PopupMobile, Menu) {

Init Measurement Widget:

define([

    'dojo/_base/declare',

    'dijit/_WidgetBase',

    'esri/dijit/Measurement',

    'dojo/aspect',

    'dojo/_base/lang',

    'dojo/dom-construct',

    'dojo/topic'

], function (declare, _WidgetBase, Measurement, aspect, lang, domConstruct, topic) {

    return declare([_WidgetBase], {

Init Export Widget:

define([

    'dojo/_base/declare',

    'dijit/_WidgetBase',

    'dijit/_TemplatedMixin',

    'dijit/_WidgetsInTemplateMixin',

    'gis/dijit/_FloatingWidgetMixin',

    'dojo/_base/lang',

    'dojo/topic',

    'dojo/_base/array',

    'dojo/json',

    'dojo/text!./Export/templates/Export.html',

    'dojo/i18n!./Export/nls/Export',

    'dijit/_Container',

    'dijit/form/Select',

    'dijit/form/Button',

    'xstyle/css!./Export/css/Export.css'

], function (

    declare,

    _WidgetBase,

    _TemplatedMixin,

    _WidgetsInTemplateMixin,

    _FloatingWidgetMixin,

    lang,

    topic,

    array,

    json,

    template,

    i18n

) {

    return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _FloatingWidgetMixin], {

Init Statistics Widget:

define([

    'dojo/_base/declare',

    'dijit/_WidgetBase',

    'dijit/_TemplatedMixin',

    'dijit/_WidgetsInTemplateMixin',

    'gis/dijit/_FloatingWidgetMixin',

    'dojo/_base/lang',

    'dojo/topic',

    'dojo/_base/array',

    'dojo/json',

    'dojo/text!./AOSStatistics/templates/Statistics.html',

    'dojo/i18n!./AOSStatistics/nls/Statistics',

    'dijit/layout/ContentPane',

    'dijit/_Container',

    'dijit/form/Select',

    'dijit/form/Button',

    'xstyle/css!./AOSStatistics/css/Statistics.css'

], function (

    declare,

    _WidgetBase,

    _TemplatedMixin,

    _WidgetsInTemplateMixin,

    _FloatingWidgetMixin,

    lang,

    topic,

    array,

    json,

    template,

    i18n

) {

    return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _FloatingWidgetMixin], {

0 Kudos
thejuskambi
Occasional Contributor III

That was exactly how I have it in my implemenation. For some reason, it used to fail to get the measurement js file. and it was not regular. I could not determine the root cause. but added the require as mentioned above, resolved the issue for me.

@Kelly - similar implementation can be found in cmv framework.

0 Kudos