This is a migrated thread and some comments may be shown as answers.

KendoMultiSelect returning [object Object]

5 Answers 1158 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Mitchell
Top achievements
Rank 1
Mitchell asked on 12 Sep 2014, 02:11 PM
I am pretty new to kendo and have been trying to get the multi select working for a little while with no final success.

I have got the dropdown widget working perfectly and I can switch out the drop down for a multiselect and visually it works but when it goes to save the data back to the datasource in the View Model it returns [object Object].  

I have set the data-value-primitive = 'true' but am really a bit stuck.  Is there something simple that I am missing.

5 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 16 Sep 2014, 08:10 AM
Hello Mitchell,

The MultiSelect widget value method returns a JavaScript Array object as a value. String value of an Array is "[object Object]". In order to assist you further, I will need more information about your current setup and erroneous behavior. A test Dojo demo that reproduces the problem will be of a great help.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Mitchell
Top achievements
Rank 1
answered on 16 Sep 2014, 09:02 AM
Hi Georgi,

I have bound an input field to the multi select and if you add a single id value it displays correctly but when you select multiple items it returns object object

Dojo is below

http://dojo.telerik.com/IFovO
0
Georgi Krustev
Telerik team
answered on 17 Sep 2014, 08:36 AM
Hello Mitchell,

The described behavior is expected, because you are trying to the set the value of an HTML input element to an Array instance. The MVVM value binding will get the model property value and will set the value of the input element like this:
//input is a reference to the input element
input.value = model.selectedItems;
 
//this is equivalent to this:
<input id="input1" />
<script>
    document.getElementById("input1").value = ["1", "2"]; //result will be [object Object]
</script>
Please note that the valuePrimitive specifies whether the MVVM value binding should set the model property to an Array of primitive values or to an Array of data objects, but in both cases the value will be Array.

Could you elaborate what do you want to see in the input element - the values of the array or serialized list of selected objects? Here is a simple demo that shows how to use MVVM source and templating to map selected items to a table.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Mitchell
Top achievements
Rank 1
answered on 18 Sep 2014, 01:34 AM
Hi Georgi,

What we are trying to achieve is connecting the multiselect value to the selectedTask.ModuleLink field of our datasource. What i am trying to achieve is saving the multi select values to a string datasource and also correctly displaying the items from a string datasource.  I can't imagine that this is a unique request so I'm assuming that I am missing something simple.

The drop down works perfectly with a single value but the multiselect behaves exactly like it does in the dojo above instead of returning a string value to the datatsource it returns an array. eg [object Object]
0
Georgi Krustev
Telerik team
answered on 19 Sep 2014, 09:10 AM
Hello Mitchell,

I am not exactly sure what the "string datasource" means. Could you elaborate a bit?

As I pointed already widget's value is an Array, which is an object and if you want to get its string representation you will need to serialize it. Such transformation are not done by the default MVVM value binding as it works with the widget and model values directly. Nevertheless, you can implement custom value binding that will serialize the object into string. Here is another Dojo demo that demonstrates how this can be implemented.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
MultiSelect
Asked by
Mitchell
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Mitchell
Top achievements
Rank 1
Share this question
or