Ticket #6690: dijit.form.ComboBox_20080507.patch

File dijit.form.ComboBox_20080507.patch, 2.8 kB (added by jaredj, 8 months ago)

Patch to make ComboBox? smarter on how it determines if 'more' should be shown.

  • form/ComboBox.js

     
    297297                                // if they are just previewing the options available. 
    298298                                this._autoCompleteText(zerothvalue); 
    299299                        } 
     300                        dataObject._maxOptions = this._maxOptions; 
    300301                        this._popupWidget.createOptions( 
    301302                                results,  
    302303                                dataObject,  
     
    502503                                                deep: true 
    503504                                        }, 
    504505                                        query: query, 
     506                                        onBegin: dojo.hitch(this, "_setMaxOptions"), 
    505507                                        onComplete: dojo.hitch(this, "_openResultList"),  
    506508                                        onError: function(errText){ 
    507509                                                console.error('dijit.form.ComboBox: ' + errText); 
     
    523525                        }, query, this), this.searchDelay); 
    524526                }, 
    525527 
     528                _setMaxOptions: function(size, request){ 
     529                         this._maxOptions = size; 
     530                }, 
     531 
    526532                _getValueField:function(){ 
    527533                        return this.searchAttr; 
    528534                }, 
     
    701707                        //this._dataObject=dataObject; 
    702708                        //this._dataObject.onComplete=dojo.hitch(comboBox, comboBox._openResultList); 
    703709                        // display "Previous . . ." button 
     710                        var displayMore = false; 
     711                        //Try to determine if we should show 'more'... 
     712                        if(dataObject._maxOptions && dataObject._maxOptions != -1){ 
     713                                if((dataObject.start + dataObject.count) < dataObject._maxOptions){ 
     714                                        displayMore = true; 
     715                                }else if((dataObject.start + dataObject.length) > (dataObject._maxOptions - 1)){ 
     716                                        //Weird return from a datastore, where a start + count > maxOptions 
     717                                        //implies maxOptions isn't really valid and we have to go into faking it. 
     718                                        //And more or less assume more if count == results.length 
     719                                        if(dataObject.count == results.length){ 
     720                                                displayMore = true; 
     721                                        } 
     722                                } 
     723                        }else if(dataObject.count == results.length){ 
     724                                //Don't know the size, so we do the best we can based off count alone. 
     725                                //So, if we have an exact match to count, assume more. 
     726                                displayMore = true; 
     727                        } 
     728 
    704729                        this.previousButton.style.display = (dataObject.start == 0) ? "none" : ""; 
    705730                        dojo.attr(this.previousButton, "id", this.id + "_prev"); 
    706731                        // create options using _createOption function defined by parent 
     
    714739                                this.domNode.insertBefore(menuitem, this.nextButton); 
    715740                        }, this); 
    716741                        // display "Next . . ." button 
    717                         this.nextButton.style.display = (dataObject.count == results.length) ? "" : "none"; 
    718                         dojo.attr(this.nextButton,"id", this.id + "_next") 
     742                        this.nextButton.style.display = displayMore ? "" : "none"; 
     743                        dojo.attr(this.nextButton,"id", this.id + "_next"); 
    719744                }, 
    720745 
    721746                clearResultList: function(){ 
     
    10101035 
    10111036                var start = args.start || 0, 
    10121037                        end = ("count" in args && args.count != Infinity) ? (start + args.count) : items.length ; 
     1038                args.onBegin(items.length, args); 
    10131039                args.onComplete(items.slice(start, end), args); 
    10141040                return args; // Object 
    10151041                // TODO: I don't need to return the length?