AutoComplete

Description

The AutoComplete widget offers suggestions as a user types that can come from a local or remote data.

Official Kendo UI AutoComplete documentation

Examples

  • Basic Example
  • Passing additional options
  • Using global options

This example demonstrates passing the basic options required by the AutoComplete plugin.

<input data-bind="kendoAutoComplete: { data: choices, value: selectedChoice }" />
<hr/>
Selected: <strong data-bind="text: selectedChoice"> </strong>
var ViewModel = function() {
   this.choices = ko.observableArray(["apple", "orange", "banana"]);
   this.selectedChoice = ko.observable();
};

                            ko.applyBindings(new ViewModel());

Selected:

This example demonstrates binding against objects for the source data and specifying the property to use for the value. The addChoice button also shows that the choices are kept in sync as the observableArray bound to the data receives new items.

<input type="checkbox" data-bind="checked: isEnabled" /> Enabled<br/>
<input class="search-query" data-bind="value: search, valueUpdate: 'afterkeydown'" placeholder="enter search term" /><br/>
<hr/>
<button class="btn" data-bind="click: addChoice">Add Choice</button>
<hr/>
<input data-bind="kendoAutoComplete: { dataTextField: 'name', data: choices,
               value: selectedChoice, search: search, enabled: isEnabled }" />
<hr/>
Selected: <strong data-bind="text: selectedChoice"> </strong>
var ViewModel = function() {
    this.choices = ko.observableArray([
        { id: "1", name: "apple"},
        { id: "2", name: "orange"},
        { id: "3", name: "banana"}
    ]);

    this.selectedChoice = ko.observable();
    this.isEnabled = ko.observable(true);
    this.search = ko.observable();
    this.addChoice = function() {
        var num = this.choices().length + 1;
        this.choices.push({ id: num, name: "new" + num});
    };
};

                            ko.applyBindings(new ViewModel());
Enabled




Selected:

This example demonstrates the ability to configure options globally by setting properties in ko.bindingHandlers.kendoAutoComplete.options. This helps to simplify the markup for settings that can be used as a default for all instances of this widget.

<input data-bind="kendoAutoComplete: { data: choices, value: selectedChoice }" />
<hr/>
Selected: <strong data-bind="text: selectedChoice"> </strong>
var ViewModel = function() {
   this.choices = ko.observableArray(["apple", "orange", "banana"]);
   this.selectedChoice = ko.observable();
};

//search text by what it contains rather than what is starts with
ko.bindingHandlers.kendoAutoComplete.options.filter = "contains";

                            ko.applyBindings(new ViewModel());

Selected:

Live Options

The kendoAutoComplete.md binding accepts all of the options that can be specified for the widget. However, when bound against an observable, these live options will update the widget or respond to updates from interactions with the widget.
enabled

Determines if users can interact with the field

value

The value of the field as selected by the user or set in the view model

data

An array, observableArray, or kendo.data.dataSource of options

search

When the value bound to this is updated, a search will be performed based on its value

widget

If specified, will populate an observable with a reference to the actual widget