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:
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:
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:
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:




There are no comments for this entry.
[Add Comment] [Subscribe to Comments]