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

Unexpected selected value in MVVM when only 1 item in source

1 Answer 9 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Matjaz
Top achievements
Rank 1
Matjaz asked on 06 Sep 2014, 08:36 PM
When dataSource has only one item, widget automatically select it, but selected item in MVVM is null. I would expected that this 2 things are synchronize.
demo just click "click for selected value" button.

1 Answer, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 08 Sep 2014, 10:58 AM
Hello Matjaz,

In general, MVVM value binding updates the model value on widget change, which will not be raised on load. Hence if you need to update the model based on the selected value after widget data binding, then you will need to trigger change event manually. This approach will work for multiple widgets too. I will suggest you wire the dataBound event and call trigger("change") there:
Copy Code
function updateModel(e) {
            var widget = e.sender;
 
            setTimeout(function() {
                widget.trigger("change");
            });
};
Check the updated demo page.

Let me know if this does not work for you.

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
DropDownList
Asked by
Matjaz
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or