Sanborn
Sanborn

Reputation: 289

Angular KendoUI Combobox initial model value

I am having trouble two-way data-binding to an object. Here is an example of the setup:

<select kendo-combo-box 
        k-data-source="objectList"
        k-placeholder="'Content Type'"
        k-data-text-field="'title'"
        k-filter="'contains'"
        k-ng-model="selectedObject"
        k-on-change="doSomeStuff()"></select>

This works fine except if the default value of selectedValue is ex:

{
  title: 'defaultValue',
  value: someValue 
}

I would expect that this would be reflected in the combobox as the selected item. However the combobox is converting the Object to a string and the selected value is [object Object]. On initialization it does not respect the k-data-text-field property.

I cannot figure out how to do this and I think that what I'm trying to do should be the expected behaviour. Does anyone know how to do this?

Upvotes: 2

Views: 2035

Answers (1)

Josh
Josh

Reputation: 44906

The issue is that you are using k-data-text-field without also specifying a k-data-value-field.

Without this Kendo has no way to determine what the actual value is it should be binding to when calling .value() on the widget, so it just does a .toString() on the whole object.

From the kendo docs:

Important When dataTextField is defined, the dataValueField option also should be set.

You simply need to add some way for kendo to uniquely identify your object in the list for binding.

k-data-value-field="'value'"

Here is an example showing what that might look like:

http://dojo.telerik.com/Ukije

Upvotes: 1

Related Questions