Ticket #6005: FormValidation.2.patch

File FormValidation.2.patch, 3.6 kB (added by nathan, 11 months ago)

Update to formValidationPatch - which contains a test case.

  • dijit/tests/form/test_validateForm.html

     
     1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
     2        "http://www.w3.org/TR/html4/strict.dtd"> 
     3<html> 
     4        <head> 
     5                <title>Test Form Validate Function</title> 
     6 
     7                <style type="text/css"> 
     8                        @import "../../../dojo/resources/dojo.css"; 
     9                        @import "../css/dijitTests.css"; 
     10                </style> 
     11 
     12                <script type="text/javascript" src="../../../dojo/dojo.js" 
     13                        djConfig="isDebug: true, parseOnLoad: true, extraLocale: ['de-de', 'en-us']"></script> 
     14                <script type="text/javascript" src="../_testCommon.js"></script> 
     15 
     16                <script type="text/javascript"> 
     17                        dojo.require("dijit.form.ValidationTextBox"); 
     18                        dojo.require("dijit.form.DateTextBox"); 
     19                        dojo.require("dijit.form.Button"); 
     20                         
     21                        dojo.require("dijit.form.Form"); 
     22                        dojo.require("dojo.parser");    // scan page for widgets and instantiate them 
     23                </script> 
     24        </head> 
     25 
     26        <body> 
     27                <h1 class="testTitle">Dijit Form Validation Test</h1> 
     28                <form dojoType="dijit.form.Form" id="form1" action="" name="example" method=""> 
     29                        <table> 
     30                                <tr> 
     31                                        <td><label for="name">Name:</label></td> 
     32                                        <td><input id="name" dojoType="dijit.form.ValidationTextBox"  
     33                                                required="true" name="name" /></td> 
     34                                </tr> 
     35                                <tr> 
     36                                        <td><label for="birth">Birthdate (before 2006-12-31):</label></td> 
     37                                        <td><input id="birth" dojoType="dijit.form.DateTextBox"  
     38                                                required="true" name="birth" constraints="{max:'2006-12-31'}" /></td> 
     39                                </tr> 
     40                                <tr> 
     41                                        <td><label for="notes">Notes (optional)</label></td> 
     42                                        <td><input id="notes" dojoType="dijit.form.TextBox"  
     43                                                name="notes" /></td> 
     44                                </tr> 
     45                        </table> 
     46                        <button dojoType="dijit.form.Button"> 
     47                                <script type="dojo/method" event="onClick"> 
     48                                        if (dijit.byId("form1").validate()){ 
     49                                                window.alert("Form is valid!"); 
     50                                        } 
     51                                </script> 
     52                                Validate Form 
     53                        </button> 
     54                </form> 
     55        </body> 
     56</html> 
  • dijit/form/ValidationTextBox.js

     
    105105                                } 
    106106                        } 
    107107                        this.displayMessage(message); 
     108                        return isValid; 
    108109                }, 
    109110 
    110111                // currently displayed message 
     
    169170 
    170171                validate: function(){ 
    171172                        this.valueNode.value = this.toString(); 
    172                         this.inherited(arguments); 
     173                        return this.inherited(arguments); 
    173174                }, 
    174175 
    175176                setAttribute: function(/*String*/ attr, /*anything*/ value){ 
  • dijit/form/Form.js

     
    3333                        }); 
    3434                }, 
    3535 
     36                validate: function(){ 
     37                        // summary: returns if the form is valid - same as isValid - but 
     38                        //                      provides a few additional (ui-specific) features. 
     39                        //                      1 - it will highlight any sub-widgets that are not 
     40                        //                              valid 
     41                        //                      2 - it will call focus() on the first invalid  
     42                        //                              sub-widget 
     43                        var didFocus = false; 
     44                        return dojo.every(dojo.map(this.getDescendants(), function(widget){ 
     45                                // Need to set this so that "required" widgets get their  
     46                                // state set. 
     47                                widget._hasBeenBlurred = true; 
     48                                var valid = !widget.validate || widget.validate(); 
     49                                if (!valid && !didFocus) { 
     50                                        // Set focus of the first non-valid widget 
     51                                        widget.focus(); 
     52                                        didFocus = true; 
     53                                } 
     54                                return valid; 
     55                        }), "return item;"); 
     56                }, 
     57                 
    3658                setValues: function(/*object*/obj){ 
    3759                        // summary: fill in form values from a JSON structure 
    3860