Select to view content in your preferred language

on selection complete runs multiple times

1794
3
Jump to solution
02-22-2017 11:26 AM
LindaDunklee
New Contributor III

I have a button that is being pressed to select features based on a query the user inputs.  The function works, but the on "selection-complete" part is firing multiple times.  When the button is clicked the first time, it fires once.  When it is clicked the second time, it fires twice, etc.  Is there any way to prevent this behavior?  I want to include more in the on complete function but cannot because it is looping multiple times.

Sites.selectFeatures(siteSelection, FeatureLayer.SELECTION_NEW);
// when selection is complete, zoom to the selected features
Sites.on("selection-complete", function(){
   map.setExtent(graphicsUtils.graphicsExtent(Sites.getSelectedFeatures()), true);

});

where site selection is defined by:

siteSelection = new Query();
siteSelection.returnGeometry = true;
siteSelection.outFields = ["*"];

siteSelection.where = queryField + " LIKE '%" + queryText + "%'";

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Linda,

   It sounds like you are adding the on selection complete event handler in your code more than once then. The can sometimes happen when a developer mistakenly add the event handler inside a function that gets called more then once in their code.

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Emeritus

Linda,

   It sounds like you are adding the on selection complete event handler in your code more than once then. The can sometimes happen when a developer mistakenly add the event handler inside a function that gets called more then once in their code.

LindaDunklee
New Contributor III

I moved the on selection complete function outside of the function running on click of the button and it worked.  Thanks for the help.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Linda,

   Glad to help.

Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.

0 Kudos