Is there an "on dijit created" event?

941
6
05-27-2014 12:36 PM
JeffPace
MVP Alum

i need to hook an onclick event to an element that doesnt exist until a dijit is created

 

 

 editorWidget = new Editor(params,'editorDiv');       
        editorWidget.startup();

          //override attribute button to show attribute pane
           function openAttribute(){
               
               registry.byId("EditContainer").selectChild(registry.byId("editAttributePane"));
          };
            //element doesnt exist until editorWidget is done being created, so sometimes this works, sometimes it doesnt
              registry.byId('btnAttributes').attr('onClick', openAttribute);

 

 

but the registry.byId('btnAttributes') is null until the editor dijit is done being created.  I would prefer not to set timeouts (i even tried 3 seconds, seems 50/50 that it would work)

 

Is there a way to figure out that the editor dijit is done starting up?

0 Kudos
6 Replies
RobertoPepato
Occasional Contributor II
Have you tried dojo/ready (not the domReady! plugin)?

See the notes on Dijits/Widgets on the domReady! documentation: http://dojotoolkit.org/reference-guide/1.9/dojo/domReady.html#dojo-domready.

Best,

Roberto Pepato
0 Kudos
JeffPace
MVP Alum
ok, but since this is an esri dijit, called from within a custom widget, I am not sure to put the ready code.

Basically,
1.the dom structure is there.
2. user logins in.  On successful login, creating my custom editing Widget is called.
3. Feature layers and attribute inspector load.  Once they are loading, esri's editor dijit is created (startup called).
4. Once the dijit is created, i need to hook an onclick method to one of the edit toolbar functions.  However, I never know when its dom elements will exist.
0 Kudos
UjjwalNarayan1
New Contributor II
Can you attach/remove the button click handler in the editor widgets onShow / onHide events?


Otherwise extend the Editor widget class and fire an event in your custom widget's startup method. Something like this might work..

define(["esri/dijit/editing/Editor"], function(Editor), 

return declare('my.custom.editor', [Editor], {

   constructor: function(opts) {

   },

   startup: function() {
     this.inherited(arguments);
     this.emit("esri-widget-startup", {});
   }
});
0 Kudos
JeffPace
MVP Alum
well, in true hacky code fashion, i decided just to loop and wait

          //override attribute button to show attribute pane
           function openAttribute(){          
               registry.byId("EditContainer").selectChild(registry.byId("editAttributePane"));
           };
            //element doesnt exist until editorWidget is done being created, so sometimes this works, sometimes it doesnt
           function waitForWidget() {
                var widget = registry.byId('btnAttributes');
                if (!widget) {
                    setTimeout(waitForWidget, 500); // setTimeout(func, timeMS, params...)
                } else {
                    // Set location on form here if it isn't in getLocation()
                    widget.attr('onClick', openAttribute);
                }
            }
            waitForWidget();
0 Kudos
BjornSvensson
Esri Regular Contributor
Jeff, we are planning to add a "load" event to the Editor dijit at version 3.10.  This should solve your problem about knowing when the Editor dijit has been loaded.
JeffPace
MVP Alum
awesome thank you!!
0 Kudos