Give us a call 203-379-0773

Changing the Highlight of our AutoCompleteComboBox

A prospect approached me about our AutoCompleteComboBox.

I noticed that the highlight of the AutoComplete text is done in bold. That means if I am using a custom font I have to embed both the normal and the bold font for the highlight to show up.

The highlighting in our Flex AutoComplete Component is done using a the htmlText property of a label. If you are embedding a custom font, and the bold version of that font is not available, you won't see the highlight. This is confirmed in the bold section of the Flex htmlText Documentation.

ItemRenderers make this aspect of our AutoCompleteComboBox completely customizable. I demonstrated this in one of the early Flextras Friday Lunch episodes. You can also view the sample and the source code. The sample is downloadable as part of our free developer edition.

The custom itemRenderer is an extension of the label. It listens to the dataChange event and modifies the label's htmlText property using some regEx to find the typed text. I'll show you the code:

public function onDataChange(e:FlexEvent):void{
var ld : AutoCompleteListData = AutoCompleteListData(this.listData)

var label : String = data.FirstName + ' ' + data.LastName + ' ' + data.Email
if(ld.typeAheadText != ''){
var regEx : RegExp = new RegExp(ld.typeAheadText ,'ig');
this.htmlText = label.replace(regEx , '<b>$&</b>');
} else {
this.htmlText = label;
}
}

First, the custom renderer gets the AutoCompleteListData. This is an extension of the listData class.

The code then generates the string for our label. The AutoComplete's default renderer supports the labelField and labelFunction, but this custom renderer sample accesses properties directly in the data object.

The regex uses the i flag, which tells the search to ignore the case. The replace tag function just encloses our typed text with bold. You could use different colors, or underlines as alternatives to bold. Or you could roll your own.

The prospect went on to ask if there was a way to select every instance of the type ahead text. That is done with a simple mod of our itemRenderer. Just add the 'g' flag tot he regex expression, like this:

var regEx : RegExp = new RegExp(ld.typeAheadText ,'ig');

I updated the sample to include the multiple selection:

How do I prevent typing in the AutoComplete Flex Component once the dataProvider is empty?

This question comes in from a client using our AutoCompleteComboBox. Note, I modded his original question to make it more appropriate for blog posting.

I'm letting my users type ahead to find a state, but right now, it's allowing them to just keep typing if the text they've entered doesn't match an existing entry.

I was looking for a property that would restrict selection / value to the data provider, but I didn't see any obvious properties that would do that.

What's your recommendation to enable that?

If I understand the request, we want to prevent users from typing further when the dataProvider's length drops down to zero. There isn't an explicit property built into our AutoCompleteComboBox that will do that.

But, we can implement it pretty easy. We just need to listen to the autoCompleteDataProviderFiltered event, check the dataProvider's length, and if it is zero reset the TypeAheadText.

This might make some more sense with some code. First here is our AutoCompleteComboBox:

<flextras:AutoCompleteComboBox id="ACCB" dataProvider="{myDB2}"
autoCompleteEnabled="true"
autoCompleteDataProviderFiltered="onDataProviderFiltered()" />

The code is listening for the autoCompleteDataProviderFiltered event and running an event handler. This event is dispatched by the component after the dataProvider has been filtered.

Inside our event handler, we want to check the dataProvider's length:

public function onDataProviderFiltered():void{
if(ListCollectionView(ACCB.dataProvider).length == 0){

}
}

If the dataProvider's length is not 0; then we do nothing. The component can continue to operate as it is. If the dataProvider is zero, we want to strip off the character that the user just typed, using a line like this:

public function onDataProviderFiltered():void{
if(ListCollectionView(ACCB.dataProvider).length == 0){

ACCB.autoCompleteSetTypeAheadText(
ACCB.typeAheadTextValue.substring(0,ACCB.typeAheadTextValue.length-1));

}
}

It uses the type ahead text property, which represents what the user typed, and removes the last character from it using the substring method of the String Class.

It resets the type ahead text using the autoCompleteSetTypeAheadText method.

You can view a sample application or the full source code:

Flextras Friday Lunch - Episode 21 - 06/26/2009 - Flash Builder 4: Network Monitor

This is episode twenty-one of the Flextras Friday Lunch podcast, originally from June 26th, 2009. In this episode, I talk about the Network Monitor in Flash Builder 4 and use our AutoCompleteComboBox from a database demo to show you how it can watch calls to the remote server.

Flextras Friday Lunch is a short demo followed by open Q&A that occur every Friday at 1pm EST. The presentations take place over Connect. You can find out what time this occurs in your own time zone at TimeAndDate.com.

I hope I can help answer some of your questions at the next one.

Notes

Subscribe

Contact

Using the Flextras AutoComplete as an ItemEditor

One of our future customers was playing around with the developer edition of the Flextras AutoCompleteComboBox and asked if the AutoCompleteComboBox could be used as an itemEditor inside a DataGrid. I had not tried it before, but I thought I'd create a quick example for him and everyone else.

First you need a dataProvider, and I grabbed some names from Smallville, a TV series about Young Superman:

public var myAC : ArrayCollection = new ArrayCollection([
    {firstName:'Jeffry',lastName:'Houser',id:1, company:'DotComIt'},
    {firstName:'Clark',lastName:'Kent',id:2, company:'Daily Planet'},
    {firstName:'Jimmy',lastName:'Olsen',id:3, company:'Daily Planet'},
    {firstName:'Chloe',lastName:'Sullivan',id:3, company:'Isis Foundation'},
    {firstName:'Lana',lastName:'Lang',id:3, company:'Isis Foundation'},
    {firstName:'Lex',lastName:'Luthor',id:3, company:'LuthorCorp'},
]);

Then add in a DataGrid:

<mx:DataGrid dataProvider="{myAC}" editable="true" itemEditEnd="onItemEditEnd(event)">
</mx:DataGrid>

Any DataGrid needs some columns, so we add in this column:

<mx:DataGridColumn width="150" editorDataField="selectedItem" >
    <mx:itemRenderer>
        <mx:Component>
            <mx:Label text="{data.company}" />
        </mx:Component>
    </mx:itemRenderer>
</mx:DataGridColumn>

The DataGrid has an itemRenderer which displays the company. In theory we could just use the dataField property, but I implemented it using an itemRenderer.

Lets add in an AutoCompleteComboBox itemEditor. For this sample, I used an in-line itemRenderer:

<mx:itemEditor>
    <mx:Component>
        <flextras:AutoCompleteComboBox dataChange="onDataChange()"
            dataProvider="{companyList}" autoCompleteEnabled="true" labelField="company" valueField="company">

            <mx:Script>
                <![CDATA[
                    import mx.collections.ArrayCollection;
                    [Bindable]
                    public var companyList : ArrayCollection = new ArrayCollection([
                            {company:'Daily Planet'},
                            {company:'DotComIt'},
                            {company:'Isis Foundation'},
                            {company:'LuthorCorp'}
                    ]);

                    public function onDataChange():void{
                        this.selectedValue = data.company;
                    }
                                            
        
                ]]>

            </mx:Script>
        </flextras:AutoCompleteComboBox>
    </mx:Component>
</mx:itemEditor>

It's a big chunk of code here, so bear with me. The top level component is the Flextras AutoCompleteComboBox. AutoCompleteEnabled is true. The labelField and valueField are set to company. valueField relates to the selectedValue functionality of our AutoCompleteComboBox. It makes it easy to set the value based on data in your dataProvider's objects without having to loop and find the index yourself.

There is a mini dataProvider defined in the AutoComplete, which contains the possibly values that can be chosen for the company property of our objects. In the onDataChange event, we reset the selectedValue. And it just works.

Here is a link to the source code, or a full size swf. Or you can play below:

What sample can I build that will help turn you into a customer?

Flextras Friday Lunch - Episode 14 - 05/08/2009 - AutoComplete From a Remote DataSource

This is episode Fourteen of the Flextras Friday Lunch podcast, originally broadcast on May 8th, 2009. In this episode, I demonstrate the Flextras AutoCompleteComboBox being populated from a database. The AutoComplete from a database Functionality is now released and available for download.

Flextras Friday Lunch is a short demo followed by open Q&A that occur every Friday at 1pm EST. The presentations take place over Connect. You can find out what time this occurs in your own time zone at TimeAndDate.com.

Subscribe via iTunes

I hope I can help answer some of your questions at the next one.

Notes

Contact

How do I Style your AutoCompleteComboBox?

One of our future customers registered and downloaded our developer edition. He wasn't quite sure how to style it. Here are his own words:

I'm testing your AutoComplete combo with my app that is heavily styled. What component is that so that i can attempt to style it to match my app?

Thanks for the question, and I'm sure we can help with that.

The Flextras AutoCompleteComboBox is based off the Flex ComboBox. Any styling that is in the ComboBox should also work with our AutoCompleteComboBox.

We added one new style to our component, that is autoCompleteTextInputStyleName. This is a pass through style and it used to style the text input where people type in the text to filter the list for AutoComplete purposes. It will support any styling that the TextInput uses.

More information on the component and the styles are in our full docs. We are always available to answer any questions you may have.

Flextras Friday Lunch - Episode 12 - 04/24/2009

This is episode twelve of the Flextras Friday Lunch podcast, originally broadcast on April 24th, 2009. In this episode I discuss creating your own itemRenderes with the Flextras AutoCompleteComboBox. The conversation led us to a discussion on using relative paths from within a Flex application.

Flextras Friday Lunch is a short demo followed by open Q&A that occur every Friday at 1pm EST. The presentations take place over Connect. You can find out what time this occurs in your own time zone at TimeAndDate.com.

Subscribe via iTunes

I hope I can help answer some of your questions at the next one.

Notes

Contact

Flextras Friday Lunch - Episode 11 - 04/17/2009

This is the eleventh episode of the Flextras Friday Lunch podcast, originally broadcast on April 17th, 2009. In this episode I demonstrate creating a custom filter function for the AutoComplete portion of our AutoCompleteComboBox.

User questions directed me to topics such as podcast editing, OOP Ideology, and We Didn't Start the Fire Internet Parodies.

Flextras Friday Lunch is a short demo followed by open Q&A that occur every Friday at 1pm EST. The presentations take place over Connect. You can find out what time this occurs in your own time zone at TimeAndDate.com.

I hope I can help answer some of your questions at the next one.

Notes

Contact

Flextras Friday Lunch - Episode 10 - 04/10/2009

This is the tenth episode of the Flextras Friday Lunch podcast, originally broadcast on April 10th, 2009. In this episode I unveil the AutoCompleteComboBox.

At the time of the recording, the AutoCompleteComboBox did not fully support database filtering, however a new version was later released that does.

Flextras Friday Lunch is a short demo followed by open Q&A that occur every Friday at 1pm EST. The presentations take place over Connect. You can find out what time this occurs in your own time zone at TimeAndDate.com.

I hope I can help answer some of your questions at the next one.

Notes

Contact

Flextras Friday Lunch - Episode 8 - 03/27/2009

This is the eight episode of the Flextras Friday Lunch podcast, originally broadcast on March 27th, 2009. In this episode I spoke about customizing the highlighting of the AutoCompleteComboBox.

Flextras Friday Lunch is a short demo followed by open Q&A that occur every Friday at 1pm EST. The presentations take place over Connect. You can find out what time this occurs in your own time zone at TimeAndDate.com.

I hope I can help answer some of your questions at the next one.

Notes

Contact

More Entries