Select to view content in your preferred language

onClick listener

1294
9
Jump to solution
04-28-2014 07:31 AM
TimWitt
Deactivated User
Hey everybody,

I am playing around with an onClick listener and I am stuck. I am writing my whole application in AMD style.

For an easy example I just wanted an alert message to popup when I click on the map, when a button is toggled to true. When the button is toggled to false I don't want the alert to popup when I click the map.

Here is the code I have so far:

      var identifyListener;               function activateIdentify(){         if (dom.byId("identifyDiv").checked) {           identifyListener = map.on("click", executeIdentifyTask);         }          else {           identifyListener.remove();         }       }              function disableIdentify() {         dom.byId("identifyDiv").unchecked;         identifyListener.remove();       }              function executeIdentifyTask(){         alert("Click");       };


And here is the corresponding button:

<div id="Button1"><button id="identifyDiv" data-dojo-type="dijit/form/ToggleButton" data-dojo-props="iconClass:'dijitCheckBoxIcon', checked: false" onClick="activateIdentify();" >Identify</button> </div>


Thanks for any help!

Tim
0 Kudos
1 Solution

Accepted Solutions
LoriGonzalez
Deactivated User
Removing the onClick from the property from the control and connecting it in the code worked for me.


[HTML]  <div id="Button1"><button id="identifyDiv" data-dojo-type="dijit/form/ToggleButton"
                   data-dojo-props="iconClass:'dijitCheckBoxIcon', checked: false" >Identify</button> </div> [/HTML]
dijit.byId("identifyDiv").on("click", activateIdentify)        function activateIdentify(evt) {            console.log("activating");            if (dijit.byId("identifyDiv").checked) {                identifyListener = map.on("click", executeIdentifyTask);            }            else {                identifyListener.remove();            }        }         function disableIdentify() {            dom.byId("identifyDiv").unchecked;            identifyListener.remove();        }         function executeIdentifyTask() {            alert("Click");        };

View solution in original post

0 Kudos
9 Replies
KenBuja
MVP Esteemed Contributor
Do you have the function activateIdentify inside the require statement? If so, it's a problem of scope. What you should do is something like

on(dom.byId("identifyDiv"), "click", function (){
    activateIdentify();
});
0 Kudos
TimWitt
Deactivated User
This is what I am trying to accomplish http://gis.stackexchange.com/questions/11374/toggle-identify-with-button

I am just having a hard time incorporating the answer into the example and trying to translate it into AMD.
0 Kudos
LuciHawkins
Frequent Contributor
Hi,

You might try it this way:

var identifyListener;
     

      function activateIdentify(){
        if (dom.byId("identifyDiv").checked) {
          identifyListener = dojo.connect(map, "onClick", executeIdentifyTask);
        }
        else {
          dojo.disconnect(identifyListener);
        }
      }
           
      function executeIdentifyTask(){
        alert("Click");
      };


Luci
0 Kudos
TimWitt
Deactivated User
Hey Luci,

I tried it this way, but it wouldn't work. 😞

Tim
0 Kudos
LuciHawkins
Frequent Contributor
Do you have other onclick events happening in your app?
0 Kudos
TimWitt
Deactivated User
Luci,

this is my full app http://jsfiddle.net/j76Yw/7/

Thanks for taking the time!

Tim
0 Kudos
TimWitt
Deactivated User
Anybody have any idea?
0 Kudos
LoriGonzalez
Deactivated User
Removing the onClick from the property from the control and connecting it in the code worked for me.


[HTML]  <div id="Button1"><button id="identifyDiv" data-dojo-type="dijit/form/ToggleButton"
                   data-dojo-props="iconClass:'dijitCheckBoxIcon', checked: false" >Identify</button> </div> [/HTML]
dijit.byId("identifyDiv").on("click", activateIdentify)        function activateIdentify(evt) {            console.log("activating");            if (dijit.byId("identifyDiv").checked) {                identifyListener = map.on("click", executeIdentifyTask);            }            else {                identifyListener.remove();            }        }         function disableIdentify() {            dom.byId("identifyDiv").unchecked;            identifyListener.remove();        }         function executeIdentifyTask() {            alert("Click");        };
0 Kudos
TimWitt
Deactivated User
Lori,

thank you!

Tim
0 Kudos