Changeset 12189
- Timestamp:
- 01/28/08 22:28:52 (12 months ago)
- Location:
- dijit/trunk
- Files:
-
- 1 modified
- 1 copied
-
form/Hidden.js (copied) (copied from dojox/trunk/widget/FormWidgets.js) (2 diffs)
-
tests/form/Form.html (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dijit/trunk/form/Hidden.js
r12143 r12189 1 dojo.provide("dojox.widget.FormWidgets"); 2 dojo.experimental("dojox.widget.FormWidgets"); 1 dojo.provide("dijit.form.Hidden"); 3 2 4 3 dojo.require("dijit._Widget"); 5 4 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, 5 dojo.declare("dijit.form.Hidden", 6 [dijit._Widget, dijit._Templated], 96 7 { 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, 98 10 // which responds to dijit.form.Form, and degrades. 99 11 // 100 12 // example: 101 // | <input type="hidden" dojoType="d ojox.widget.Hidden" name="foo" value="bar" />13 // | <input type="hidden" dojoType="dijit.form.Hidden" name="foo" value="bar" /> 102 14 // 15 16 // name: String 17 // Name used when submitting form; same as "name" attribute or plain HTML elements 103 18 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 110 27 getValue: function(){ 111 28 // summary: Normalized getter for this input … … 123 40 } 124 41 }); 125 126 dojo.declare("dojox.widget.TextArea",dojox.widget.Hidden,{127 // summary: A Simple textarea that degrades, and responds to128 // minimal LayoutContiner usage, and works with dijit.form.Form129 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 23 23 dojo.require("dijit.form.DateTextBox"); 24 24 dojo.require("dijit.form.Button"); 25 dojo.require("dijit.form.MultiSelect"); 26 dojo.require("dijit.form.Hidden"); 25 27 dojo.require("dijit.Editor"); 26 28 … … 51 53 cb2: ["2", "3"], 52 54 r2: "2", 55 ms1: ["VA", "WA"], 56 h1: "hidden", 53 57 richtext: "<h1>original</h1><p>This is the default content</p>" 54 58 }; … … 61 65 cb2: ["4"], 62 66 r2: "1", 67 ms1: ["FL", "CA"], 68 h1: "still hidden", 63 69 richtext: "<h1>changed</h1><p>This is the changed content set by setValues</p>" 64 70 }; … … 201 207 </td> 202 208 </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 203 233 <tr> 204 234 <td>Editor widget</td><td>richtext</td>