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

4 posts, 0 answers
  1. Matthew
    Matthew avatar
    1 posts
    Member since:
    Apr 2012

    Posted 12 Apr 2012 Link to this post

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

    Posted 17 Apr 2012 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Mark
    Mark avatar
    15 posts
    Member since:
    Aug 2015

    Posted 10 Jun in reply to Georgi Krustev Link to this post

    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.
  5. Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    347 posts

    Posted 16 Jun Link to this post

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