Changeset 12183

Show
Ignore:
Timestamp:
01/28/08 01:01:39 (7 months ago)
Author:
bill
Message:

Update dijit.form.Form to handle MultiSelect?. Refs #5359.

Files:
2 modified

Legend:

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

    r12067 r12183  
    4949                                                w.setAttribute('checked', (dojo.indexOf(values, w.value) != -1)); 
    5050                                        }); 
     51                                }else if(widgets[0].setValues){ 
     52                                        // it's a multi-select 
     53                                        widgets[0].setValues(values); 
    5154                                }else{ 
    5255                                        // otherwise, values is a list of values to be assigned sequentially to each widget 
     
    135138                        var obj = { }; 
    136139                        dojo.forEach(this.getDescendants(), function(widget){ 
    137                                 var value = (widget.getValue && !widget._getValueDeprecated) ? widget.getValue() : widget.value; 
    138140                                var name = widget.name; 
    139141                                if(!name){ return; } 
    140142 
    141                                 // Store widget's value(s) as a scalar, except for checkboxes which are automatically arrays 
    142                                 if(typeof widget.checked == 'boolean'){ 
    143                                         if(/Radio/.test(widget.declaredClass)){ 
    144                                                 // radio button 
    145                                                 if(widget.checked){ 
    146                                                         dojo.setObject(name, value, obj); 
     143                                if(widget.getValues){ 
     144                                        // A multi-value widget (ex: MultiSelect) 
     145                                        dojo.setObject(name, widget.getValues(), obj); 
     146                                }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(widget.checked){ 
     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(widget.checked){ 
     165                                                                ary.push(value); 
     166                                                        } 
    147167                                                } 
    148168                                        }else{ 
    149                                                 // checkbox/toggle button 
    150                                                 var ary=dojo.getObject(name, false, obj); 
    151                                                 if(!ary){ 
    152                                                         ary=[]; 
    153                                                         dojo.setObject(name, ary, obj); 
    154                                                 } 
    155                                                 if(widget.checked){ 
    156                                                         ary.push(value); 
    157                                                 } 
    158                                         } 
    159                                 }else{ 
    160                                         // plain input 
    161                                         dojo.setObject(name, value, obj); 
     169                                                // plain input 
     170                                                dojo.setObject(name, value, obj); 
     171                                        } 
    162172                                } 
    163173                        }); 
  • dojox/trunk/widget/tests/test_FormWidgets.html

    r12143 r12183  
    33<html> 
    44<head> 
    5         <title>Testing degradable form widgets | The Dojo Toolkit</title> 
     5        <title>Testing degradeable form widgets | The Dojo Toolkit</title> 
    66 
    77        <link rel="stylesheet" type="text/css" media="screen" 
     
    232232                                console.log('getting values from split:'); 
    233233                                dojo.query("#splitC > select").forEach(function(n){ 
    234                                         // dumpt the select's name attrib, and the value(s) selected: 
     234                                        // dump the select's name attrib, and the value(s) selected: 
    235235                                        console.log(n.name,dijit.byNode(n).getValue()); 
    236236                                });