Changeset 12189

Show
Ignore:
Timestamp:
01/28/08 22:28:52 (12 months ago)
Author:
bill
Message:

"Hidden" widget, copied over from dojox.
The "Hidden" widget is basically equivalent to <input dojoType="dijit.form.TextBox?" type="hidden"> but with less overhead; not sure if it's worth having a separate widget for hidden input fields but adding for now.
Fixes #5700.

Also checking in forgotten updates to Form test for MultiSelect?. Refs #5359.

Location:
dijit/trunk
Files:
1 modified
1 copied

Legend:

Unmodified
Added
Removed
  • dijit/trunk/form/Hidden.js

    r12143 r12189  
    1 dojo.provide("dojox.widget.FormWidgets"); 
    2 dojo.experimental("dojox.widget.FormWidgets"); 
     1dojo.provide("dijit.form.Hidden"); 
    32 
    43dojo.require("dijit._Widget"); 
    54 
    6 dojo.declare("dojox.widget.Select",dijit._Widget,{ 
    7         // summary: Wrapper for a native select multiple="true" element to 
    8         //              interact with dijit.form.Form 
    9         // 
    10         // name: String 
    11         //              The name of this form element 
    12         name: "", 
    13          
    14         postCreate: function(){ 
    15                 this.inherited(arguments); 
    16                 this._selected = []; 
    17                 this.connect(this.domNode,"onchange","_setSelected"); 
    18         }, 
    19          
    20         addSelected: function(/* dojox.widget.Select */select){ 
    21                 // summary: Appends the selected nodes af an passed Select widget 
    22                 //                      instance to this Select widget. 
    23                 // 
    24                 // example: 
    25                 // |    // move all the selected values from "bar" to "foo" 
    26                 // |    dijit.byId("foo").addSelected(dijit.byId("bar")); 
    27                  
    28                 select._selected.forEach(function(n){ 
    29                         this.domNode.appendChild(n); 
    30                 },this); 
    31                 dojo.hitch(select,"_setSelected"); 
    32                 this._setSelected(); 
    33  
    34         }, 
    35                                          
    36         getSelected: function(){ 
    37                 // summary: Access the NodeList of the selected options directly 
    38                 return this._setSelected(); // dojo.NodeList 
    39         }, 
    40          
    41         getValues: function(){ 
    42                 // summary: Returns an array of the selected options value's 
    43                 var vals = []; 
    44                 this._setSelected().forEach(function(n){ 
    45                         vals.push(n.value); 
    46                 }); 
    47                 return vals; // Array 
    48         }, 
    49          
    50         getValue: function(){ 
    51                 // summary: serialize the values of the selected nodes 
    52                 return this.getValues(); // Array 
    53         }, 
    54          
    55         setValue: function(/* Array */values){ 
    56                 // summary: Set the value(s) of this Select based on passed values 
    57                 dojo.query("option",this.domNode).forEach(function(n){ 
    58                         n.selected = (dojo.indexOf(values,n.value) === 0); 
    59                 }); 
    60         }, 
    61                  
    62         invertSelection: function(onChange){ 
    63                 // summary: Invert the selection 
    64                 // onChange: Boolean 
    65                 //              If null, onChange is not fired. 
    66                 this._selected = dojo.query("option",this.domNode).filter(function(n){ 
    67                         n.selected = !n.selected; 
    68                         return n.selected; // Boolean 
    69                 }); 
    70                 if(onChange){ this.onChange(); } 
    71         }, 
    72  
    73         _setSelected: function(e){ 
    74                 // summary: Re-populate the selected NodeList 
    75                 this._selected = dojo.query("option",this.domNode).filter(function(n){ 
    76                         return n.selected; // Boolean 
    77                 }); 
    78                 if(e && e.type){ this.onChange(this._selected); } 
    79                 return this._selected; // dojo.NodeList 
    80         }, 
    81          
    82         // for layout widgets: 
    83         resize: function(/* Object */size){ 
    84                 dojo.style(this.domNode,"width",size.w+"px"); 
    85                 dojo.style(this.domNode,"height",size.h+"px"); 
    86         }, 
    87          
    88         onChange: function(e){ 
    89                 // summary: a stub -- over-ride, or connect 
    90         } 
    91          
    92 }); 
    93  
    94 dojo.declare("dojox.widget.Hidden", 
    95         dijit._Widget, 
     5dojo.declare("dijit.form.Hidden", 
     6        [dijit._Widget, dijit._Templated], 
    967        { 
    97         // summary: A widget corosponding to a native input type="hidden" element, 
     8        // summary: 
     9        //              A widget corresponding to a native input type="hidden" element, 
    9810        //              which responds to dijit.form.Form, and degrades. 
    9911        // 
    10012        // example: 
    101         //      |       <input type="hidden" dojoType="dojox.widget.Hidden" name="foo" value="bar" /> 
     13        //      |       <input type="hidden" dojoType="dijit.form.Hidden" name="foo" value="bar" /> 
    10214        // 
     15 
     16        // name: String 
     17        //              Name used when submitting form; same as "name" attribute or plain HTML elements 
    10318        name: "", 
    104          
    105         postCreate: function(){ 
    106                 this.inherited(arguments); 
    107                 this.connect(this.domNode,"onchange","onChange"); 
    108         }, 
    109          
     19 
     20        // value: String 
     21        //              Corresponds to the native HTML <input> element's attribute. 
     22        value: "", 
     23 
     24        templateString: "<input type='hidden' dojoAttachEvent='onchange: onChange'>", 
     25        attributeMap: {value:"domNode", name:"domNode", id:"domNode"}, 
     26 
    11027        getValue: function(){ 
    11128                // summary: Normalized getter for this input 
     
    12340        } 
    12441}); 
    125  
    126 dojo.declare("dojox.widget.TextArea",dojox.widget.Hidden,{ 
    127         // summary: A Simple textarea that degrades, and responds to 
    128         //              minimal LayoutContiner usage, and works with dijit.form.Form 
    129          
    130         resize: function(/* Object */size){ 
    131                 dojo.style(this.domNode,"width",size.w+"px"); 
    132                 dojo.style(this.domNode,"height",size.h+"px"); 
    133         } 
    134          
    135 }); 
  • dijit/trunk/tests/form/Form.html

    r12044 r12189  
    2323                dojo.require("dijit.form.DateTextBox"); 
    2424                dojo.require("dijit.form.Button"); 
     25                dojo.require("dijit.form.MultiSelect"); 
     26                dojo.require("dijit.form.Hidden"); 
    2527                dojo.require("dijit.Editor"); 
    2628 
     
    5153                                                        cb2: ["2", "3"], 
    5254                                                        r2: "2", 
     55                                                        ms1: ["VA", "WA"], 
     56                                                        h1: "hidden", 
    5357                                                        richtext: "<h1>original</h1><p>This is the default content</p>" 
    5458                                                }; 
     
    6165                                                        cb2: ["4"], 
    6266                                                        r2: "1", 
     67                                                        ms1: ["FL", "CA"], 
     68                                                        h1: "still hidden", 
    6369                                                        richtext: "<h1>changed</h1><p>This is the changed content set by setValues</p>" 
    6470                                                }; 
     
    201207</td> 
    202208</tr> 
     209 
     210<tr> 
     211        <td>Multi-select</td><td>ms1</td> 
     212        <td> 
     213                <select id="ms1" multiple="true" name="ms1" 
     214                        dojoType="dijit.form.MultiSelect" 
     215                        style="height:100px; width:175px; border:5px solid #ededed;"> 
     216 
     217                        <option value="TN">Tennessee</option> 
     218                        <option value="VA" selected="true">Virginia</option> 
     219                        <option value="WA" selected="true">Washington</option> 
     220                        <option value="FL">Florida</option> 
     221                        <option value="CA">California</option> 
     222 
     223                </select> 
     224        </td> 
     225</tr> 
     226 
     227<tr> 
     228        <td>Hidden input</td> 
     229        <td>h1</td> 
     230        <td><input id="h1" name="h1" dojoType="dijit.form.Hidden" value="hidden"></td> 
     231</tr> 
     232 
    203233<tr> 
    204234<td>Editor widget</td><td>richtext</td>