Ticket #6299: 6299.patch

File 6299.patch, 6.4 kB (added by doughays, 10 months ago)

patch for review

  • form/Button.js

     
    4949                // summary: callback when the user mouse clicks the button portion 
    5050                if(this._onClick(e) === false){ // returning nothing is same as true 
    5151                        dojo.stopEvent(e); 
    52                 }else if(this.type=="submit"){ // see if a nonform widget needs to be signalled 
     52                }else if(this.type=="submit" && !this.focusNode.form){ // see if a nonform widget needs to be signalled 
    5353                        for(var node=this.domNode; node.parentNode/*#5935*/; node=node.parentNode){ 
    5454                                var widget=dijit.byNode(node); 
    5555                                if(widget && typeof widget._onSubmit == "function"){ 
  • form/Form.js

     
    284284                accept: "", 
    285285                target: "", 
    286286 
    287                 templateString: "<form dojoAttachPoint='containerNode' name='${name}'></form>", 
     287                templateString: "<form dojoAttachPoint='containerNode' dojoAttachEvent='onreset:_onReset,onsubmit:_onSubmit' name='${name}'></form>", 
    288288 
    289289                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: ""}), 
    291291 
    292292                execute: function(/*Object*/ formContents){ 
    293293                        //      summary: 
     
    316316                                } 
    317317                        } 
    318318                        this.inherited(arguments); 
    319                         dojo.attr(this.domNode, 'onreset', dojo.hitch(this, this._onReset)); 
    320319                }, 
    321320 
    322                 onReset: function(){  
     321                onReset: function(/*Event?*/e){  
    323322                        //      summary: 
    324323                        //              Callback when user resets the form. This method is intended 
    325324                        //              to be over-ridden. When the `reset` method is called 
     
    328327                        return true; // Boolean 
    329328                }, 
    330329 
    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){ 
    333341                                this.reset(); 
    334342                        } 
    335                         return false; // Boolean 
     343                        dojo.stopEvent(e); 
     344                        return false; 
    336345                }, 
    337346 
    338                 // TODO: remove ths function beginning with 2.0 
    339                 _onSubmit: function(){ 
     347                _onSubmit: function(e){ 
    340348                        var fp = dijit.form.Form.prototype; 
     349                        // TODO: remove ths if statement beginning with 2.0 
    341350                        if(this.execute != fp.execute || this.onExecute != fp.onExecute){ 
    342351                                dojo.deprecated("dijit.form.Form:execute()/onExecute() are deprecated. Use onSubmit() instead.", "", "2.0"); 
    343352                                this.onExecute(); 
    344353                                this.execute(this.getValues()); 
    345354                        } 
     355                        if(this.onSubmit(e) === false){ // only exactly false stops submit 
     356                                dojo.stopEvent(e); 
     357                        } 
    346358                }, 
    347359                 
    348360                onSubmit: function(/*Event?*/e){  
     
    354366                        //              `onSubmit` is used to compute whether or not submission 
    355367                        //              should proceed 
    356368 
    357                         if(!this.isValid()){ 
    358                                 if(e){ dojo.stopEvent(e); } 
    359                                 return false; // Boolean 
    360                         } 
    361                         return true; // Boolean 
     369                        return this.isValid(); // Boolean 
    362370                }, 
    363371 
    364372                submit: function(){ 
    365373                        // summary: 
    366374                        //              programmatically submit form if and only if the `onSubmit` returns true 
    367                         if(!!this.onSubmit()){ 
     375                        if(!(this.onSubmit() === false)){ 
    368376                                this.containerNode.submit(); 
    369377                        } 
    370378                } 
  • tests/form/Form.html

     
    145145                        } 
    146146                        return true; 
    147147                </script> 
     148                <script type="dojo/method" event="onReset"> 
     149                        return confirm('reset Form?'); 
     150                </script> 
    148151                <p>Just HTML text</p> 
    149152                <table style="border: 1px solid #9f9f9f;" cellspacing="10"> 
    150153                        <thead> 
  • tests/form/test_Form_onsubmit.html

     
    2828</head> 
    2929<body> 
    3030        <h1>Form Widget Unit Test</h1> 
    31         <form dojoType="dijit.form.Form" id="myForm"  
     31        <form dojoType="dijit.form.Form" id="myForm1"  
    3232                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> 
    3536                <select name="plop.combo" dojoType="dijit.form.ComboBox"> 
    3637                        <option value="one">one</option> 
    3738                        <option value="two">two</option> 
     
    4344 
    4445        <form dojoType="dijit.form.Form" id="myForm2"  
    4546                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> 
    4850                <select name="plop.combo" dojoType="dijit.form.ComboBox"> 
    4951                        <option value="one">one</option> 
    5052                        <option value="two">two</option> 
     
    5355                <button dojoType=dijit.form.Button type="submit">Submit</button> 
    5456                <button dojoType=dijit.form.Button type="reset">Reset</button> 
    5557        </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> 
    5686</body> 
    5787</html>