Changeset 12482
- Timestamp:
- 02/17/08 05:07:53 (11 months ago)
- Location:
- dijit/trunk
- Files:
-
- 10 modified
-
form/CheckBox.js (modified) (1 diff)
-
form/Form.js (modified) (4 diffs)
-
form/MultiSelect.js (modified) (4 diffs)
-
form/NumberTextBox.js (modified) (1 diff)
-
form/ValidationTextBox.js (modified) (1 diff)
-
form/_FormWidget.js (modified) (3 diffs)
-
tests/form/Form.html (modified) (5 diffs)
-
tests/form/test_CheckBox.html (modified) (1 diff)
-
tests/form/test_MultiSelect.html (modified) (3 diffs)
-
tests/form/test_validate.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
dijit/trunk/form/CheckBox.js
r12387 r12482 44 44 }, 45 45 46 _getValueDeprecated: false, // remove when _FormWidget: getValueis removed46 _getValueDeprecated: false, // remove when _FormWidget:_getValueDeprecated is removed 47 47 getValue: function(){ 48 48 // summary: get the value of the widget. 49 49 return (this.checked ? this.value : false); 50 }, 51 52 reset: function(){ 53 this.inherited(arguments); 54 this.setAttribute('value', this._resetValueAttr); 55 }, 56 57 postCreate: function(){ 58 this.inherited(arguments); 59 this._resetValueAttr = this.value; 50 60 } 51 61 } -
dijit/trunk/form/Form.js
r12387 r12482 26 26 // 27 27 28 reset: function(){ 29 dojo.forEach(this.getDescendants(), function(widget){ 30 if(widget.reset){ 31 widget.reset(); 32 } 33 }); 34 }, 35 28 36 setValues: function(/*object*/obj){ 29 37 // summary: fill in form values from a JSON structure … … 49 57 w.setValue(dojo.indexOf(values, w.value) != -1); 50 58 }); 51 }else if(widgets[0]. setValues){52 // it 's a multi-select53 widgets[0].setValue s(values);59 }else if(widgets[0]._multiValue){ 60 // it takes an array (e.g. multi-select) 61 widgets[0].setValue(values); 54 62 }else{ 55 63 // otherwise, values is a list of values to be assigned sequentially to each widget … … 141 149 if(!name){ return; } 142 150 143 if(widget.getValues){ 144 // A multi-value widget (ex: MultiSelect) 145 dojo.setObject(name, widget.getValues(), obj); 151 // Single value widget (checkbox, radio, or plain <input> type widget 152 var value = (widget.getValue && !widget._getValueDeprecated) ? widget.getValue() : widget.value; 153 154 // Store widget's value(s) as a scalar, except for checkboxes which are automatically arrays 155 if(typeof widget.checked == 'boolean'){ 156 if(/Radio/.test(widget.declaredClass)){ 157 // radio button 158 if(value !== false){ 159 dojo.setObject(name, value, obj); 160 } 161 }else{ 162 // checkbox/toggle button 163 var ary=dojo.getObject(name, false, obj); 164 if(!ary){ 165 ary=[]; 166 dojo.setObject(name, ary, obj); 167 } 168 if(value !== false){ 169 ary.push(value); 170 } 171 } 146 172 }else{ 147 // Single value widget (checkbox, radio, or plain <input> type widget 148 var value = (widget.getValue && !widget._getValueDeprecated) ? widget.getValue() : widget.value; 149 150 // Store widget's value(s) as a scalar, except for checkboxes which are automatically arrays 151 if(typeof widget.checked == 'boolean'){ 152 if(/Radio/.test(widget.declaredClass)){ 153 // radio button 154 if(value !== false){ 155 dojo.setObject(name, value, obj); 156 } 157 }else{ 158 // checkbox/toggle button 159 var ary=dojo.getObject(name, false, obj); 160 if(!ary){ 161 ary=[]; 162 dojo.setObject(name, ary, obj); 163 } 164 if(value !== false){ 165 ary.push(value); 166 } 167 } 168 }else{ 169 // plain input 170 dojo.setObject(name, value, obj); 171 } 173 // plain input 174 dojo.setObject(name, value, obj); 172 175 } 173 176 }); … … 286 289 } 287 290 this.inherited(arguments); 291 dojo.attr(this.domNode, 'onreset', dojo.hitch(this, this._onReset)); 292 }, 293 294 // onReset: Function 295 // Callback when user resets the form 296 // (user can override - return false to cancel the default action) 297 onReset: function(){ 298 return true; 299 }, 300 301 _onReset: function(){ 302 if(this.onReset()){ 303 this.reset(); 304 } 305 return false; 288 306 }, 289 307 -
dijit/trunk/form/MultiSelect.js
r12182 r12482 38 38 }, 39 39 40 getValues: function(){ 40 _getValueDeprecated: false, // remove when _FormWidget:_getValueDeprecated is removed in 2.0 41 getValue: function(){ 41 42 // summary: Returns an array of the selected options' values 42 43 return this.getSelected().map(function(n){ … … 45 46 }, 46 47 47 setValues: function(/* Array */values){ 48 _multiValue: true, // for Form 49 setValue: function(/* Array */values){ 48 50 // summary: Set the value(s) of this Select based on passed values 49 51 dojo.query("option",this.domNode).forEach(function(n){ … … 59 61 n.selected = !n.selected; 60 62 }); 61 if(onChange){ this.onChange(this.getValues()); }63 this._handleOnChange(this.getValue(), onChange==true); 62 64 }, 63 65 64 66 _onChange: function(/*Event*/ e){ 65 this. onChange(this.getValues());67 this._handleOnChange(this.getValue(), true); 66 68 }, 67 69 … … 73 75 }, 74 76 75 onChange: function(/*String[] */ l){76 // summary: a stub -- over-ride, or connect77 postCreate: function(){ 78 this._onChange(); 77 79 } 78 80 }); -
dijit/trunk/form/NumberTextBox.js
r11788 r12482 33 33 34 34 format: function(/*Number*/ value, /*Object*/ constraints){ 35 if(typeof value == "string") { return value; } 35 36 if(isNaN(value)){ return ""; } 36 37 if(this.editOptions && this._editing){ -
dijit/trunk/form/ValidationTextBox.js
r12453 r12482 136 136 }, 137 137 138 reset: function(){ 139 this.inherited(arguments); 140 this._hasBeenBlurred = false; 141 }, 142 138 143 //////////// INITIALIZATION METHODS /////////////////////////////////////// 139 144 -
dijit/trunk/form/_FormWidget.js
r12387 r12482 224 224 // summary: set the value of the widget. 225 225 this._lastValue = newValue; 226 if(this._lastValueReported == undefined && priorityChange === null){227 this._ lastValueReported = newValue;226 if(this._lastValueReported == undefined && (priorityChange === null || !this._onChangeActive)){ 227 this._resetValue = this._lastValueReported = newValue; 228 228 } 229 229 if((this.intermediateChanges || priorityChange || priorityChange === undefined) && … … 231 231 this._lastValueReported = newValue; 232 232 if(this._onChangeActive){ this.onChange(newValue); } 233 } 234 }, 235 236 reset: function(){ 237 if(this._resetValue !== undefined){ 238 if(this.setValue && !this._getValueDeprecated){ 239 this.setValue(this._resetValue, true); 240 }else{ 241 this.setAttribute(this._onChangeMonitor, this._resetValue); 242 } 233 243 } 234 244 }, … … 244 254 clearTimeout(this._layoutHackHandle); 245 255 this.inherited(arguments); 246 },247 248 postCreate: function(){249 this._lastValueReported = this[this._onChangeMonitor];250 256 }, 251 257 -
dijit/trunk/tests/form/Form.html
r12387 r12482 62 62 }; 63 63 64 // we resetthe form to these values64 // we change the form to these values 65 65 var changed = { 66 66 foo: {bar: {baz: {quux: d("2005-01-01")} } }, … … 74 74 st1: "new simple line 1\nnew simple line 2", 75 75 richtext: "<h1>changed</h1><p>This is the changed content set by setValues</p>", 76 filename: "" 77 }; 78 // we reset the form to these values 79 var reset = { 80 foo: {bar: {baz: {quux: d("2007-12-30")} } }, 81 available: {from: d("2005-01-02"), to: d("2006-01-02")}, 82 plop: {combo: "one"}, 83 cb2: ["2", "3"], 84 r2: "2", 85 ms1: ["VA", "WA"], 86 h1: "hidden", 87 t1: "line 1\nline 2", 88 st1: "simple line 1\nsimple line 2", 89 richtext: "<h1>changed</h1><p>This is the changed content set by setValues</p>", // not a form element, so not reset 76 90 filename: "" 77 91 }; … … 93 107 }); 94 108 109 }, 110 function resetTest(){ 111 dijit.byId("myForm").reset(); 112 doh.is( dojo.toJson(reset), dojo.toJson(dijit.byId("myForm").getValues()) ); 95 113 } 96 114 ] … … 111 129 http://www.utexas.edu/teamweb/cgi-bin/generic.cgi 112 130 http://www.tipjar.com/cgi-bin/test --> 113 <form dojoType="dijit.form.Form" id="myForm" encType="multipart/form-data" action="" method="" onsubmit="alert('Attempting to submit form w/values:\n'+dojo.toJson(this.getValues(),true));if(this.isValid()){return confirm('Form is valid, press OK to submit');}else{alert('Form contains invalid data. Please correct first');return false;}"> 131 <form dojoType="dijit.form.Form" id="myForm" encType="multipart/form-data" action="" method="" 132 onreset="return confirm('Press OK to reset widget values')" 133 onsubmit="alert('Attempting to submit form w/values:\n'+dojo.toJson(this.getValues(),true));if(this.isValid()){return confirm('Form is valid, press OK to submit');}else{alert('Form contains invalid data. Please correct first');return false;}" 134 > 114 135 <p>Just HTML text</p> 115 136 <table border=2> … … 273 294 <button dojoType=dijit.form.Button onClick="setValues();">Set Values to form!</button> 274 295 <button dojoType=dijit.form.Button type="submit">Submit</button> 296 <button dojoType=dijit.form.Button type="reset">Reset</button> 275 297 </form> 276 298 -
dijit/trunk/tests/form/test_CheckBox.html
r11982 r12482 83 83 <input type="button" onclick='dijit.byId("cb7").setAttribute("disabled",false);' value="enable" /> 84 84 <input type="button" onclick='dijit.byId("cb7").setValue("fish");' value='set value to "fish"' /> 85 <input type="button" onclick='dijit.byId("cb7").reset();' value='Reset value+checked' /> 85 86 <span>"onChange" handler updates: [<span id="onvaluechangedoutput"></span>]</span> 86 87 <br> -
dijit/trunk/tests/form/test_MultiSelect.html
r12182 r12482 73 73 // there is only one debug button 74 74 dojo.query(".debug").connect("onclick",function(e){ 75 console.log('select getValue s:',dijit.byId("select").getValues());76 console.log('select2 getValue s:',dijit.byId("select2").getValues());77 console.log('select3 getValue s:',dijit.byId("select3").getValues());75 console.log('select getValue:',dijit.byId("select").getValue()); 76 console.log('select2 getValue:',dijit.byId("select2").getValue()); 77 console.log('select3 getValue:',dijit.byId("select3").getValue()); 78 78 }); 79 79 … … 116 116 </form> 117 117 118 <button class="debug">call getValue s()</button>118 <button class="debug">call getValue()</button> 119 119 120 120 <h3>markup:</h3> … … 134 134 <br><br> 135 135 <button class='invert' id="i3">invert markup list</button> 136 <button class='set' id="s1" onclick="dijit.byId('select3').setValue s(['VA', 'WA']);">set markup list to [VA, WA]</button>136 <button class='set' id="s1" onclick="dijit.byId('select3').setValue(['VA', 'WA']);">set markup list to [VA, WA]</button> 137 137 </body> 138 138 </html> -
dijit/trunk/tests/form/test_validate.html
r12044 r12482 220 220 <button onclick="dijit.byId('q08eur').setAttribute('disabled',true);return false">Disable</button> 221 221 <button onclick="dijit.byId('q08eur').setAttribute('disabled',false);return false">Enable</button> 222 <button onclick="dijit.byId('q08eur').reset();return false">Reset</button> 222 223 </div> 223 224