Dojo.stopEvent didn't work due to exception
function connectGenerateChartButton() { var buttonNode = dojo.byId("generateChartButton"); dojo.connect(buttonNode, "onclick", function(evt) { console.log("Stop this event from doing a form submit."); dojo.stopEvent(evt); console.log("Publish event for the generate chart button."); dojo.publish("generateChart", ["Woohoo!"]); console.log("Done."); }); dojo.subscribe("generateChart", function(text){ generateChart(); }); }I am using pub/sub so I can be in a position to unit test my event code. (I'm decoupling the UI event and the actual business logic.) I ran into an issue with dojo.stopEvent as shown above. Originally I had the stopEvent and publish lines switched so I would publish first and then stop the event. Seems logical right? I found out that my generateChart function had an exception that propagated out to my onclick handler and my stopEvent code was being skipped because of the exception. I was getting a post anyway!
So for now I moved my stopEvent to be the first thing in this anon function. That might be best practice anyway.
Also I need to learn more about exception handling. I have a try/catch in my "main" function, but maybe that is not enough.
Comments
Post a Comment