Ticket #6299: 6299.patch
| File 6299.patch, 6.4 kB (added by doughays, 10 months ago) |
|---|
-
form/Button.js
49 49 // summary: callback when the user mouse clicks the button portion 50 50 if(this._onClick(e) === false){ // returning nothing is same as true 51 51 dojo.stopEvent(e); 52 }else if(this.type=="submit" ){ // see if a nonform widget needs to be signalled52 }else if(this.type=="submit" && !this.focusNode.form){ // see if a nonform widget needs to be signalled 53 53 for(var node=this.domNode; node.parentNode/*#5935*/; node=node.parentNode){ 54 54 var widget=dijit.byNode(node); 55 55 if(widget && typeof widget._onSubmit == "function"){ -
form/Form.js
284 284 accept: "", 285 285 target: "", 286 286 287 templateString: "<form dojoAttachPoint='containerNode' name='${name}'></form>",287 templateString: "<form dojoAttachPoint='containerNode' dojoAttachEvent='onreset:_onReset,onsubmit:_onSubmit' name='${name}'></form>", 288 288 289 289 attributeMap: dojo.mixin(dojo.clone(dijit._Widget.prototype.attributeMap), 290 { onSubmit: "",action: "", method: "", encType: "", "accept-charset": "", accept: "", target: ""}),290 {action: "", method: "", encType: "", "accept-charset": "", accept: "", target: ""}), 291 291 292 292 execute: function(/*Object*/ formContents){ 293 293 // summary: … … 316 316 } 317 317 } 318 318 this.inherited(arguments); 319 dojo.attr(this.domNode, 'onreset', dojo.hitch(this, this._onReset));320 319 }, 321 320 322 onReset: function( ){321 onReset: function(/*Event?*/e){ 323 322 // summary: 324 323 // Callback when user resets the form. This method is intended 325 324 // to be over-ridden. When the `reset` method is called … … 328 327 return true; // Boolean 329 328 }, 330 329 331 _onReset: function(){ 332 if(this.onReset()){ 330 _onReset: function(e){ 331 // create fake event so we can know if preventDefault() is called 332 var faux = { 333 returnValue: true, // the IE way 334 preventDefault: function(){ // not IE 335 this.returnValue = false; 336 }, 337 stopPropagation: function(){}, currentTarget: e.currentTarget, target: e.target 338 }; 339 // if return value is not exactly false, and haven't called preventDefault(), then reset 340 if(!(this.onReset(faux) === false) && faux.returnValue){ 333 341 this.reset(); 334 342 } 335 return false; // Boolean 343 dojo.stopEvent(e); 344 return false; 336 345 }, 337 346 338 // TODO: remove ths function beginning with 2.0 339 _onSubmit: function(){ 347 _onSubmit: function(e){ 340 348 var fp = dijit.form.Form.prototype; 349 // TODO: remove ths if statement beginning with 2.0 341 350 if(this.execute != fp.execute || this.onExecute != fp.onExecute){ 342 351 dojo.deprecated("dijit.form.Form:execute()/onExecute() are deprecated. Use onSubmit() instead.", "", "2.0"); 343 352 this.onExecute(); 344 353 this.execute(this.getValues()); 345 354 } 355 if(this.onSubmit(e) === false){ // only exactly false stops submit 356 dojo.stopEvent(e); 357 } 346 358 }, 347 359 348 360 onSubmit: function(/*Event?*/e){ … … 354 366 // `onSubmit` is used to compute whether or not submission 355 367 // should proceed 356 368 357 if(!this.isValid()){ 358 if(e){ dojo.stopEvent(e); } 359 return false; // Boolean 360 } 361 return true; // Boolean 369 return this.isValid(); // Boolean 362 370 }, 363 371 364 372 submit: function(){ 365 373 // summary: 366 374 // programmatically submit form if and only if the `onSubmit` returns true 367 if(! !this.onSubmit()){375 if(!(this.onSubmit() === false)){ 368 376 this.containerNode.submit(); 369 377 } 370 378 } -
tests/form/Form.html
145 145 } 146 146 return true; 147 147 </script> 148 <script type="dojo/method" event="onReset"> 149 return confirm('reset Form?'); 150 </script> 148 151 <p>Just HTML text</p> 149 152 <table style="border: 1px solid #9f9f9f;" cellspacing="10"> 150 153 <thead> -
tests/form/test_Form_onsubmit.html
28 28 </head> 29 29 <body> 30 30 <h1>Form Widget Unit Test</h1> 31 <form dojoType="dijit.form.Form" id="myForm "31 <form dojoType="dijit.form.Form" id="myForm1" 32 32 encType="multipart/form-data" action="" method="GET" 33 onSubmit="dojo.stopEvent(arguments[0]);"> 34 <h3>This form shouldn't submit</h3> 33 onSubmit="dojo.stopEvent(arguments[0]);" 34 onReset="dojo.stopEvent(arguments[0]);"> 35 <h3>This form shouldn't submit, nor reset</h3> 35 36 <select name="plop.combo" dojoType="dijit.form.ComboBox"> 36 37 <option value="one">one</option> 37 38 <option value="two">two</option> … … 43 44 44 45 <form dojoType="dijit.form.Form" id="myForm2" 45 46 encType="multipart/form-data" action="" method="GET" 46 onSubmit="return false;"> 47 <h3>This form <em>should</em> submit</h3> 47 onSubmit="return false;" 48 onReset="return false;"> 49 <h3>This form shouldn't submit, nor reset</h3> 48 50 <select name="plop.combo" dojoType="dijit.form.ComboBox"> 49 51 <option value="one">one</option> 50 52 <option value="two">two</option> … … 53 55 <button dojoType=dijit.form.Button type="submit">Submit</button> 54 56 <button dojoType=dijit.form.Button type="reset">Reset</button> 55 57 </form> 58 59 <form dojoType="dijit.form.Form" id="myForm3" 60 encType="multipart/form-data" action="" method="GET" 61 onSubmit="return true;" 62 onReset="return true;"> 63 <h3>This form <em>should</em> submit and reset</h3> 64 <select name="plop.combo" dojoType="dijit.form.ComboBox"> 65 <option value="one">one</option> 66 <option value="two">two</option> 67 <option value="three">three</option> 68 </select> 69 <button dojoType=dijit.form.Button type="submit">Submit</button> 70 <button dojoType=dijit.form.Button type="reset">Reset</button> 71 </form> 72 73 <form dojoType="dijit.form.Form" id="myForm4" 74 encType="multipart/form-data" action="" method="GET" 75 onSubmit="void(0)" 76 onReset="void(0)"> 77 <h3>This form <em>should</em> submit and reset</h3> 78 <select name="plop.combo" dojoType="dijit.form.ComboBox"> 79 <option value="one">one</option> 80 <option value="two">two</option> 81 <option value="three">three</option> 82 </select> 83 <button dojoType=dijit.form.Button type="submit">Submit</button> 84 <button dojoType=dijit.form.Button type="reset">Reset</button> 85 </form> 56 86 </body> 57 87 </html>