Select to view content in your preferred language

Cannot start editing with button

1298
7
Jump to solution
02-21-2013 10:33 AM
JakeSkinner
Esri Esteemed Contributor
I am attempting to start and stop an edit session using two buttons within a web app.  The edit session begins, but I have to click the "Start Editing" button twice to have it start.  The edit session will stop when I click the "Stop Editing" button, but then I am unable to start another edit session.  Does anyone know why both of these issues may be occurring?  Below is the code:

var editorWidget;  function startEditing(){     map.addLayers(editLayers);     dojo.connect(map, "onLayersAddResult", initEditing); }  function stopEditing(){     editorWidget.destroy(); }  function initEditing(results) {         var featureLayerInfos = dojo.map(results, function(result) {           return {             "featureLayer": result.layer           };         });         var settings = {           map: map,           layerInfos: featureLayerInfos         };         var params = {           settings: settings         };                  editorWidget = new esri.dijit.editing.Editor(params, 'editorDiv');                  var options = {snapKey:dojo.keys.copyKey};         map.enableSnapping(options);                  editorWidget.startup(); }
0 Kudos
1 Solution

Accepted Solutions
RyanKoehnen
Occasional Contributor
I've found that when you call destroy(), it also deletes the container div you put the editorWidget in, 'editorDiv' in your case. So when you call editorWidget.startup() after a destroy, it has no place to put it since 'editorDiv' no longer exists. You'll need to re-append editorDiv into the DOM before calling editorWidget.startup() if you want to start editing again after a destroy() call.

View solution in original post

0 Kudos
7 Replies
RyanKoehnen
Occasional Contributor
I've found that when you call destroy(), it also deletes the container div you put the editorWidget in, 'editorDiv' in your case. So when you call editorWidget.startup() after a destroy, it has no place to put it since 'editorDiv' no longer exists. You'll need to re-append editorDiv into the DOM before calling editorWidget.startup() if you want to start editing again after a destroy() call.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Hi Ryan,

Thanks for the reply.  You are right, the div was being deleted after calling destroy().  I updated the stopEditing function to recreate the div:

function stopEditing(){
    editorWidget.destroy();   
    dojo.create("div", {id: "editorDiv"}, "leftPane");
}


Not sure why I have to click Start Editing twice to begin the initial edit session, but each stop/start of the edit session works with no problems after that.  Thanks for the help!
0 Kudos
JamesTrier
Occasional Contributor
Sorry to revive an older thread, but I found the thread while debugging a similar activate editing button in my app. 

I have a 'Done' button in the container with my editor that turns the editor off, and then a menu selection that turns editing on.  When the user clicks 'Done' I call 'editorWidget.destroy()' and remove the DOM nodes.  When the editor is reactivated I recreate the nodes.

However, in my console, I get an error message - "Tried to register widget with id==editorDiv but that id is already registered".  I thought calling destroy() prevents that from happening?  The editor seems to work despite the error, but I don't want this error to display to users. 

Any thoughts on this?  Thanks,

Jim
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Hi Jim,

I was able to reproduce the same error message.  Calling destroy() should prevent this.  After calling the destroy method, I checked the dijit.registry and the editorDiv widget was not there.  I'm not sure where else this could be stored.  This may be a bug. 

I'm curious, when you enable editing do you have to execute your menu selection twice when you start an edit session for the first time?  When I start my edit session for the first time, I have to click on the 'Start Editing' button twice.
0 Kudos
StevenGriffith
Deactivated User
function startEditing(){
    map.addLayers(editLayers);
    dojo.connect(map, "onLayersAddResult", initEditing);
}


Should be:

function startEditing(){
    dojo.connect(map, "onLayersAddResult", initEditing);
    map.addLayers(editLayers);
}


This way, you're making the callback connection *before* adding the layers, instead of after. This should prevent you from having to click the 'start editing' button twice.

Steve G.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Thanks, Steven!
0 Kudos
JamesTrier
Occasional Contributor
Hi Jim,

I was able to reproduce the same error message.  Calling destroy() should prevent this.  After calling the destroy method, I checked the dijit.registry and the editorDiv widget was not there.  I'm not sure where else this could be stored.  This may be a bug. 

I'm curious, when you enable editing do you have to execute your menu selection twice when you start an edit session for the first time?  When I start my edit session for the first time, I have to click on the 'Start Editing' button twice.


Steven beat me to it (by some time, I need to check the forum more often!).  Since my code has the dojo.connect call before adding the layer, I did not see the behavior you mentioned. 

About calling destroy() on the widget, I found the issue.  Destroy() doesn't do enough - according to the Dojo documentation, destroy() doesn't remove a widget's descendants.  So the error crops up because parts of the widget are never destroyed.  I changed the destroy() call to destroyRecursive(false) and it solved the problem.  Now, each time the 'Edit' button is activated, it creates a 'new' editor, so there's no more conflicts.

From the Dojo documentation:

This is the generic "destructor" function that all widget users should call to cleanly discard with a widget. Once a widget is destroyed, it is removed from the manager object.
 

source: http://dojotoolkit.org/api/1.7/dijit/_Widget/destroyRecursive

Hope this helps Jake!
0 Kudos