Ticket #6021: 6021.patch

File 6021.patch, 5.3 kB (added by haysmark, 5 months ago)

Fixes #6021. Added fetchProperties mixin attribute to ComboBox? to support both present and future dojo.data attributes. Added tests to test_ComboBox demonstrating sort both in markup and programmatically.

  • form/ComboBox.js

     
    2727                //              Reference to data provider object used by this ComboBox 
    2828                store: null, 
    2929 
     30                // fetchProperties: Object 
     31                //              Mixin to the dojo.data store's fetch. 
     32                //              For example, to set the sort order of the ComboBox menu, pass: 
     33                //              {sort:{attribute:"name",descending:true}} 
     34                fetchProperties:{}, 
     35 
    3036                // query: Object 
    3137                //              A query that can be passed to 'store' to initially filter the items, 
    3238                //              before doing further filtering based on `searchAttr` and the key. 
     
    520526                        // otherwise, if the user types and the last query returns before the timeout, 
    521527                        // _lastQuery won't be set and their input gets rewritten 
    522528                        this.searchTimer=setTimeout(dojo.hitch(this, function(query, _this){ 
    523                                 var dataObject = this.store.fetch({ 
     529                                var fetch = { 
    524530                                        queryOptions: { 
    525531                                                ignoreCase: this.ignoreCase,  
    526532                                                deep: true 
     
    534540                                        }, 
    535541                                        start:0, 
    536542                                        count:this.pageSize 
    537                                 }); 
     543                                }; 
     544                                dojo.mixin(fetch, _this.fetchProperties); 
     545                                var dataObject = _this.store.fetch(fetch); 
    538546 
    539547                                var nextSearch = function(dataObject, direction){ 
    540548                                        dataObject.start += dataObject.count*direction; 
     
    587595 
    588596                constructor: function(){ 
    589597                        this.query={}; 
     598                        this.fetchProperties={}; 
    590599                }, 
    591600 
    592601                postMixInProperties: function(){ 
     
    10721081                        items = dojo.query("> option", this.root).filter(function(option){ 
    10731082                                return (option.innerText || option.textContent || '').match(matcher); 
    10741083                        } ); 
     1084                if(args.sort){ 
     1085                        items.sort(dojo.data.util.sorter.createSortFunction(args.sort, this)); 
     1086                } 
    10751087                findCallback(items, args); 
    10761088        }, 
    10771089 
  • tests/form/test_ComboBox.html

     
    5656                                query:{type:'country'}, 
    5757                                searchAttr:"name" 
    5858                        }, dojo.byId("progCombo2")); 
     59 
     60                        new dijit.form.ComboBox({ 
     61                                name:"prog3", 
     62                                autoComplete:false, 
     63                                store:store2, 
     64                                query:{type:'country'}, 
     65                                searchAttr:"name", 
     66                                fetchProperties: {sort:[{attribute: 'name', descending: true}]} 
     67                        }, dojo.byId("progCombo3")); 
    5968                } 
    6069                dojo.addOnLoad(init); 
    6170 
     
    8998                                onChange="dojo.byId('oc1').value=arguments[0]" 
    9099                                pageSize="30" 
    91100                > 
    92                         <option></option> 
    93101                        <option>Alabama</option> 
    94102                        <option>Alaska</option> 
    95103                        <option>American Samoa</option> 
     
    240248                <p>A ComboBox with an initial query.  (Limits list to items with type = country.)</p> 
    241249                <input id="progCombo2"> 
    242250                <hr> 
     251                <p>A ComboBox with an ItemFileReadStore and a descending sort.  (Limits list to items with type = country.)</p> 
     252                <input id="progCombo3"> 
     253                <hr> 
     254                <p>A ComboBox with a option tags, autoComplete=true, pageSize=30, and a descending sort.</p> 
     255                <select 
     256                                name="state6" 
     257                                dojoType="dijit.form.ComboBox" 
     258                                style="width:50%;font-size:200%;font-family:Courier;" 
     259                                name="foo.bar1" 
     260                                autoComplete="true" 
     261                                onChange="dojo.byId('oc1').value=arguments[0]" 
     262                                pageSize="30" 
     263                                fetchProperties="{sort:[{attribute: 'name', descending: true}]}" 
     264                > 
     265                        <option>Alabama</option> 
     266                        <option>Alaska</option> 
     267                        <option>American Samoa</option> 
     268                        <option>Arizona</option> 
     269                        <option>Arkansas</option> 
     270                        <option>Armed Forces Europe</option> 
     271                        <option>Armed Forces Pacific</option> 
     272                        <option>Armed Forces the Americas</option> 
     273                        <option>California</option> 
     274                        <option>Colorado</option> 
     275                        <option>Connecticut</option> 
     276                        <option>Delaware</option> 
     277                        <option>District of Columbia</option> 
     278                        <option>Federated States of Micronesia</option> 
     279                        <option>Florida</option> 
     280                        <option>Georgia</option> 
     281                        <option>Guam</option> 
     282                        <option>Hawaii</option> 
     283                        <option>Idaho</option> 
     284                        <option>Illinois</option> 
     285                        <option>Indiana</option> 
     286                        <option selected>Iowa</option> 
     287                        <option>Kansas</option> 
     288                        <option>Kentucky</option> 
     289                        <option>Louisiana</option> 
     290                        <option>Maine</option> 
     291                        <option>Marshall Islands</option> 
     292                        <option>Maryland</option> 
     293                        <option>Massachusetts</option> 
     294                        <option>Michigan</option> 
     295                        <option>Minnesota</option> 
     296                        <option>Mississippi</option> 
     297                        <option>Missouri</option> 
     298                        <option>Montana</option> 
     299                        <option>Nebraska</option> 
     300                        <option>Nevada</option> 
     301                        <option>New Hampshire</option> 
     302                        <option>New Jersey</option> 
     303                        <option>New Mexico</option> 
     304                        <option>New York</option> 
     305                        <option>North Carolina</option> 
     306                        <option>North Dakota</option> 
     307                        <option>Northern Mariana Islands</option> 
     308                        <option>Ohio</option> 
     309                        <option>Oklahoma</option> 
     310                        <option>Oregon</option> 
     311                        <option>Pennsylvania</option> 
     312                        <option>Puerto Rico</option> 
     313                        <option>Rhode Island</option> 
     314                        <option>South Carolina</option> 
     315                        <option>South Dakota</option> 
     316                        <option>Tennessee</option> 
     317                        <option>Texas</option> 
     318                        <option>Utah</option> 
     319                        <option>Vermont</option> 
     320                        <option>Virgin Islands, U.S.</option> 
     321                        <option>Virginia</option> 
     322                        <option>Washington</option> 
     323                        <option>West Virginia</option> 
     324                        <option>Wisconsin</option> 
     325                        <option>Wyoming</option> 
     326                <hr> 
    243327                <input type="button" value="Create one in a window" onclick="var win=window.open(window.location);"></input> 
    244328                <input type="submit"> 
    245329