KendoMultiSelect returning [object Object]

6 posts, 0 answers
  1. Mitchell
    Mitchell avatar
    3 posts
    Member since:
    Sep 2014

    Posted 12 Sep 2014 Link to this post

    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.
  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 16 Sep 2014 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Mitchell
    Mitchell avatar
    3 posts
    Member since:
    Sep 2014

    Posted 16 Sep 2014 Link to this post

    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
  5. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 17 Sep 2014 Link to this post

    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!
     
  6. Mitchell
    Mitchell avatar
    3 posts
    Member since:
    Sep 2014

    Posted 17 Sep 2014 Link to this post

    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]
  7. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 19 Sep 2014 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready