RadAutoCompleteTextView: Events

In this article you are going to learn about the RadAutoCompleteTextView events.
The events are designed to notify you whenever a particular action, in the workflow of the control, has happened. They are quite useful when it comes to executing logic based on the RadAutoCompleteTextView state.

Available events

The RadAutoCompleteTextView control exposes these events:

  • tokenAdded - triggered whenever a token is added.
  • tokenRemoved - triggered whenever a token is removed.
  • tokenSelected - triggered whenever a token is selected.
  • tokenDeselected - triggered whenever a token is deselected.
  • didAutoComplete - triggered whenever an item from the suggestions list is selected.
  • suggestionViewBecameVisible - triggered whenever the suggestion view is shown.

All of these have identical logical structure and identical workflow, the only difference between them is the event which they are observing and notifing you about.

Usage

In order to get notified when one of the above-mentioned events occur, you should use the following structure with the type of event you want to capture.

<RadAutoCompleteTextView [items]="dataItems" suggestMode="Suggest" displayMode="Tokens" 
                         (suggestionViewBecameVisible)="onSuggestionViewBecameVisible($event)"
                         (didAutoComplete)="onDidAutoComplete($event)"
                         (tokenAdded)="onTokenAdded($event)" (tokenRemoved)="onTokenRemoved($event)"
                         (tokenSelected)="onTokenSelected($event)" (tokenDeselected)="onTokenDeselected($event)">
    <SuggestionView tkAutoCompleteSuggestionView suggestionViewHeight="300">
        <ng-template tkSuggestionItemTemplate let-item="item">
            <StackLayout orientation="vertical" padding="10">
                <Label [text]="item.text"></Label>
            </StackLayout>
        </ng-template>
    </SuggestionView>
</RadAutoCompleteTextView>
public onTokenAdded(args) {
    this.logEvent("Added Token: " + args.token.text);
}

public onTokenRemoved(args) {
    this.logEvent("Removed Token: " + args.token.text);
}

public onTokenSelected(args) {
    this.logEvent("Selected Token: " + args.token.text);
}

public onTokenDeselected(args) {
    this.logEvent("Deselected Token: " + args.token.text);
}

public onDidAutoComplete(args) {
    this.logEvent("DidAutoComplete with text: " + args.text);
}

public onSuggestionViewBecameVisible(args) {
    this.logEvent("Suggestion View Became Visible");
}

References

Want to see this scenario in action?
Check our SDK examples repo on GitHub. You will find this and many other practical examples with NativeScript UI.