is there a way to stop all other events in a dojo onBlur event handler? -
maybe i'm on wrong track...
the setup: have rather complex full dojofied web application. important part question longish form in central region of dijit.layout.bordercontainer navigation tree , action buttons in other regions.
what want do: if user did enter data , did not save, should warning message if going leave form (if navigates away, klicks "new element" button,...). better user experience, wanted give modal dialog options "save", "leave anyway", "cancel". may idea use onblur event of form, stop other events (most onclick on other widget), check changes, if there changes, display dialog, otherwise let other events continue. not want add checkchanges method non-form active elements!
for first test tried stop events...
this works
<div id="formarea" dojotype="dijit.form.form" encoding="multipart/form-data" action="" class="contentpane" region="center"> <script type="dojo/connect" event="onblur" > alert("i don't think so"); </script> </div> ...but it's ugly , can't continue
this doesn't
<div id="formarea" dojotype="dijit.form.form" encoding="multipart/form-data" action="" class="contentpane" region="center"> <script type="dojo/connect" event="onblur" args="e"> console.log("blur"); // ok e.preventdefault();//event.stopt(e)//return false //<--neither of these </script> </div> the problem if click on button outside of form, onblur triggers, can't stop onclick on button. know onblur doesn't deliver event object - e.something can't work... there way catch onclick on other element?
there afaik confirm('question?') 'deadlock' events of page that.
i have made similar setup though, way came around (except if user enters url in addressbar , hits enter) popup dialog whenever navigation tree clicked, sending user new view. consider:
---------------------------------------- | nav 1 | asset1 ( view controller ) | | nav 2 | asset2 ( hidden ) | ---------------------------------------- nav 1 default onload view, asset 1 loaded, contains 'setup page' form or similar , can changed. trick is, asset1 , asset2 derivative abstractasset in turn simple contentpane extension.
in abstractasset 'must-override-for-functionality' function called isdirty
var viewcontroller = declare("abstractasset", [dijit.contentpane], { isdirty: function() { return false; } }); declare("asset1", [viewcontroller], { startup: function() { // sets form ... // , references inputfields 'this' this.inputfields = this.form.getchildren(); // , saves (clones) state of each field var self = this; this.inputfields.foreach(function(inputwidget) { self.states[inputwidget.id] = inputwidget.get("value"); }); }, isdirty: function() { var self = this; var dirty = false; this.form.getchildren().some(input) { if(self.states[input.id] != input.get("value")) { dirty = true; return false; // breaks .some loop } return true; }); return dirty; } }) then in turn, every navigation click must call visible view controller's isdirty function in order procede. lets user clicks nav-tree (dijit.tree) row node nav 2.
var navigation = dojo.declare("navigationcontroller", [dijit.tree], { currentview : null, onload: function() { // start asset1 in viewnode default this.currentview = new asset1({ }, this.viewnode); }, onclick : function() { if(this.currentview.isdirty()) alert("i dont think so"); else { this.loadfunction(this.model.selection.getselected()); } } }); this general idea of implementing on-unload-check, need hook onclick events through 'master application controller' determine should happen. check application serves cms navigation controller , page.js:587 isdirty example
Comments
Post a Comment