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

data-bind a viewModel element to the text of a dropdownlist

3 Answers 755 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 12 Apr 2012, 03:31 PM
Hi, I am new to Kendo and would like to know how I can store the text value of a dropdownlist in a viewModel element.  I have three cascading dropdowns and the value of two of them is not what I want, it is the actual text of the dropdownlist that I need.  As the dropdownlists change I would like to have a hidden html element that has a data-bind="text: viewModel.element" so it would always have the current text of the dropdownlist.

Thank you

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 17 Apr 2012, 03:05 PM
Hello Matthew, 

There are several ways to achieve your goal, which as far I understand is to persist DDL text in hidden field:
  1. The first approach is to wire the change event of the dropdownlist and set the text of the widget to hidden field. This approach excludes the MVVM.
  2. The second approach is to create a custom MVVM binder which will get the text of the dropdownlist and will set a property of the ViewModel. This property can be bound to the hidden field. Check this jsFiddle demo for more information.

All the best,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Mark
Top achievements
Rank 1
answered on 10 Jun 2016, 06:04 PM
Georgi, we can do this onChange, but what about when the view originally loads?  IE, the dropdownlist is part of a larger viewmodel, it loads...when that DDL loads for the first time, we want to update a SPAN on the page with the TEXT from that Kendo DDL...I think we can do it with MVVM, but are having difficult time figuring it out.  HELP???  Thanks.
0
Dimiter Topalov
Telerik team
answered on 16 Jun 2016, 07:08 AM
Hi Mark,

Please check out the following demo, showing MVVM/Widget binding for multiple Kendo UI Widgets, including a DropDownList:

http://demos.telerik.com/kendo-ui/mvvm/widgets

I hope this helps.

Regards,
Dimiter Topalov
Telerik
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
Tags
MVVM
Asked by
Matthew
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Mark
Top achievements
Rank 1
Dimiter Topalov
Telerik team
Share this question
or