Packageorg.restfulx.components.rx
Classpublic class RxAutoComplete
InheritanceRxAutoComplete Inheritance mx.controls.ComboBox

This class adds integrated search capability to your Flex/AIR applications.

The idea is this:

You type some stuff into a text-field. Whatever you type up to a given number of milliseconds (say 500) will be used to create a search query to the appropriate server-side controller. That controller would typically return a super thin version of the objects (let's say just the id and the parameter such as name you were searching on). Once that is received the component switches to filtering and does the rest of the search in-memory. When you try a different search same thing happens, we try to hit the server with the initial search criteria and then switch to in-memory filtering. When you hit enter the component will call show method on the object which will hit server-side controller show action and give you an opportunity to return a full version of the object and any of it's children using to_fxml(:include) or something along those lines. If the object has already been shown then the version from the cache is returned directly.


Example
Some sample MXML code:
    <components:RxAutoComplete id="autoComplete"   
      resource="{Project}" filterFunction="filterProjectsByName" 
      "/>
    

And the filter function:
 
      private function filterProjectsByName(item:Project):Boolean { 
              var regexp:RegExp = new RegExp(autoComplete.typedText, "i"); 
              return item.name.search(regexp) != -1; 
      } 
    



Public Properties
 PropertyDefined by
  alwaysShow : Boolean = false
Always invoke show on the model independency of the currently shown status
RxAutoComplete
  chosenItem : Object
Gets currently chosen item
RxAutoComplete
  clearTextAfterFind : Boolean
Indicates if the search area should be cleared after a specific item has been found/shown
RxAutoComplete
  customSearchFunction : Function
By default RxAutoComplete will use Rx.models.reload function with metadata in append mode, which will use the current service provider.
RxAutoComplete
  enterKeyInvokesSearch : Boolean = true
If enter key is hit, invoke search
RxAutoComplete
  filterCategory : String
If provided this indicates which property should be used for filtering/search
RxAutoComplete
  filterFunction : Function
Client-side filter function.
RxAutoComplete
  lookupDelay : int = 1500
Indicates how long we should wait for before firing server request
RxAutoComplete
  lookupMinChars : int = 1
Minimum number of characters that must be provided before server request will be made
RxAutoComplete
  noResultText : String = "No Results"
Text to show if no results are found
RxAutoComplete
  onServerErrorFunction : Function
Invoked when server responds with an error
RxAutoComplete
  resource : Object
Get Rx model class this auto complete component is bound to
RxAutoComplete
  showOnEnter : Boolean = true
Indicates if a Rx.models.show operation should be performed on enter
RxAutoComplete
  typedText : String
Contains currently typed text
RxAutoComplete
  useManualSearch : Boolean = false
If set to true, do not automatically submot queries to the server
RxAutoComplete
Public Methods
 MethodDefined by
  
RxAutoComplete
  
Clear typed text without triggering dropdown show
RxAutoComplete
  
close(event:Event = null):void
RxAutoComplete
  
getStyle(styleProp:String):*
RxAutoComplete
  
invokeSearch(event:TimerEvent = null):void
Calling this function will force the control to hit the server with the search
RxAutoComplete
Protected Methods
 MethodDefined by
  
RxAutoComplete
  
keyDownHandler(event:KeyboardEvent):void
RxAutoComplete
  
textInput_changeHandler(event:Event):void
RxAutoComplete
  
updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
RxAutoComplete
Events
 EventSummaryDefined by
    RxAutoComplete
    RxAutoComplete
    RxAutoComplete
    RxAutoComplete
    RxAutoComplete
Property detail
alwaysShowproperty
public var alwaysShow:Boolean = false

Always invoke show on the model independency of the currently shown status

chosenItemproperty 
chosenItem:Object  [read-write]

Gets currently chosen item

This property can be used as the source for data binding.

Implementation
    public function get chosenItem():Object
    public function set chosenItem(value:Object):void
clearTextAfterFindproperty 
public var clearTextAfterFind:Boolean

Indicates if the search area should be cleared after a specific item has been found/shown

customSearchFunctionproperty 
public var customSearchFunction:Function

By default RxAutoComplete will use Rx.models.reload function with metadata in append mode, which will use the current service provider. If you are unhappy with any part of standard Rx index/reload processing, you can provide your own custom function here to do all the processing


Example
Example Custom Search Function that deals with online/offline custom queries
        private function customSearchFunction(clazz:Class = null, serviceResponder:ServiceResponder = null,
                     metadata:Object = null, nestedBy:Array = null):void {
           if (online) {
               trace("online search, pass through to the service provider");
             Rx.services.getServiceProvider(XMLHTTPServiceProvider.ID).index(
                 clazz, serviceResponder, metadata, nestedBy);
           } else {
             trace("do custom offline search too");
              XRx.air(function(results:Object):void { 
                 serviceResponder.result(new ResultEvent(ResultEvent.RESULT, false, false, results)); 
               }).findAll(clazz, ["name like :name", {':name': "%foo%"}]);
         }
      }
     

enterKeyInvokesSearchproperty 
public var enterKeyInvokesSearch:Boolean = true

If enter key is hit, invoke search

filterCategoryproperty 
public var filterCategory:String

If provided this indicates which property should be used for filtering/search

filterFunctionproperty 
public var filterFunction:Function

Client-side filter function. This should be complemented by the appropriate server-side search action/method.

lookupDelayproperty 
public var lookupDelay:int = 1500

Indicates how long we should wait for before firing server request

lookupMinCharsproperty 
public var lookupMinChars:int = 1

Minimum number of characters that must be provided before server request will be made

noResultTextproperty 
public var noResultText:String = "No Results"

Text to show if no results are found

onServerErrorFunctionproperty 
public var onServerErrorFunction:Function

Invoked when server responds with an error

resourceproperty 
resource:Object  [read-write]

Get Rx model class this auto complete component is bound to

This property can be used as the source for data binding.

Implementation
    public function get resource():Object
    public function set resource(value:Object):void
showOnEnterproperty 
public var showOnEnter:Boolean = true

Indicates if a Rx.models.show operation should be performed on enter

typedTextproperty 
typedText:String  [read-write]

Contains currently typed text

This property can be used as the source for data binding.

Implementation
    public function get typedText():String
    public function set typedText(value:String):void
useManualSearchproperty 
public var useManualSearch:Boolean = false

If set to true, do not automatically submot queries to the server

Constructor detail
RxAutoComplete()constructor
public function RxAutoComplete()
Method detail
clearTypedText()method
public function clearTypedText():void

Clear typed text without triggering dropdown show

close()method 
public override function close(event:Event = null):void

Parameters
event:Event (default = null)
commitProperties()method 
protected override function commitProperties():void
getStyle()method 
public override function getStyle(styleProp:String):*

Parameters
styleProp:String

Returns
*
invokeSearch()method 
public function invokeSearch(event:TimerEvent = null):void

Calling this function will force the control to hit the server with the search

Parameters
event:TimerEvent (default = null)
keyDownHandler()method 
protected override function keyDownHandler(event:KeyboardEvent):voidParameters
event:KeyboardEvent
textInput_changeHandler()method 
protected override function textInput_changeHandler(event:Event):voidParameters
event:Event
updateDisplayList()method 
protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):voidParameters
unscaledWidth:Number
 
unscaledHeight:Number
Event detail
chosenItemChangeevent 
Event object type: flash.events.Event

itemHighlightedevent  
Event object type: flash.events.Event

selectedItemChangeevent  
Event object type: flash.events.Event

typedTextChangeevent  
Event object type: flash.events.Event

unknownSelectedItemevent  
Event object type: org.restfulx.events.RxAutoCompleteItemEvent