Skip navigation
bkhatl
Currently Being Moderated

CombBox itemMatchingFunction

Feb 11, 2011 2:47 PM

I have extended a ComboBox for 2 major reasons, specialized skinning and to provide for custom item matching.  I'm having a problem with the itemMatchingFunction.  I can see the function being invoked and the appropriate items included and excluded from the resultant vector.  But what is being displayed is still the entire list if items in the data provider.  Any comments, questions or suggestions would be appreciated!

 

Thanks,

Brenda

 

  Here are some snippets of my code:

 

        public function FilteredComboBox() {
            super();
            this.openOnInput = true;
            this.itemMatchingFunction = matchingFunction;
        }

 

        public function matchingFunction(cb:ComboBox, text:String):Vector.<int> {
            var results:Vector.<int> = new Vector.<int>;
           
            var item:String;
            var entered:String = text.toLowerCase();
            var itemIdx:int;
           
            for(var idx:int = 0; idx < cb.dataProvider.length; idx++) {
                item = cb.dataProvider.getItemAt(idx) as String;
                item = item.toLowerCase();
                itemIdx = item.indexOf(entered);
                if(item.indexOf(entered) > -1) {
                    results.push(idx);
                }
            }
            return results;
        }

 
Replies
  • Currently Being Moderated
    Feb 11, 2011 3:23 PM   in reply to bkhatl

    I don't think the matchingFunction also shrinks the number of entries in the

    dropdown.  I think it just highlights one but shows all of them.

     

    There's another post today where someone is filtering their own

    ArrayCollection in order to get the number of dropdown entries to shrink.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 8, 2011 7:42 AM   in reply to bkhatl

    Try the below sample code for the scenario required. This might be helpful.

     

     

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <fx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
               
                import spark.events.IndexChangeEvent;
                import spark.events.TextOperationEvent;
               
                [Bindable]
                private var arrC:ArrayCollection = new ArrayCollection([{label:'Ronak'},{label:'Virat'},{label:'Ronaksdfsdfs f'},{label:'Ronaksdfsdf'},{label:'Ronak'},{label:'Ronak'},{label:'Rona k'},{label:'Ronak'},{label:'Ronak'},{label:'Ronak'},{label:'Ronak'}]);

     

                private var flag:Boolean = true;
               
                protected function cb_changeHandler():void
                {
                    if(flag == true)
                    {
                        cb.textInput.addEventListener(TextOperationEvent.CHANGE,changeHandler );
                        flag = false;
                    }
                   
                    // TODO Auto-generated method stub
                }
               
                private function changeHandler(e:*):void
                {
                    cb.textInput.removeEventListener(TextOperationEvent.CHANGE,changeHand ler);
                    arrC.filterFunction = doFilter;
                    arrC.refresh();
                    flag = true;
                }

     

                private function doFilter(item:Object):Boolean
                {
                    if(String(item.label).toLowerCase().indexOf(cb.textInput.text.slice(0 ,cb.textInput.selectionAnchorPosition).toLowerCase())>-1)
                    {
                        return true;
                    }
                    return false;
                }
            ]]>
        </fx:Script>
       
        <s:ComboBox id="cb" dataProvider="{arrC}"  updateComplete="cb_changeHandler()"/>
    </s:Application>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points