Switch widget and MVVM

8 posts, 1 answers
  1. Alex
    Alex avatar
    23 posts
    Member since:
    Aug 2012

    Posted 06 Sep 2012 Link to this post

    Hi! Could you provide me small example to bind model member (boolean) to Switch widget state.
    I would expect something like
    <input data-role="switch" data-bind="checked:checked"/>

    But it looks terrible and does not work. Another question: why after binding my Tabstrip looks "doubled"
    http://jsfiddle.net/GewUa/5/ 
  2. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 10 Sep 2012 Link to this post

    Hello Alex,

     
    The switch widget is initialized twice, which is not supported. I will suggest you use the data-model attribute.
    Here is the updated jsFiddle demo.

    Regards,
    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. JET
    JET avatar
    19 posts
    Member since:
    Dec 2012

    Posted 09 Mar 2014 in reply to Georgi Krustev Link to this post

    What if you have a view with a form and because of the requirements cannot use the data-model attribute to bind the information to the view, but instead bind it as Alex shows it during data-before-show or data-show? How can you bind to a switch correctly declaratively? How can you make it so that the switch does not get initialized twice?

    Please, advise!
  5. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 11 Mar 2014 Link to this post

    Hi,

    You can use View's init event to bind the view's content. Check the updated jsFiddle demo.

    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. Amitesh
    Amitesh avatar
    5 posts
    Member since:
    Aug 2010

    Posted 01 Apr 2014 in reply to Georgi Krustev Link to this post

    Hi Georgi,

    The binding for the switch on the demo actually is not working.

    Regards,

    Ikhwan
  7. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 04 Apr 2014 Link to this post

    Hello,

    Indeed, the binding does not work, because I missed to specify a namespace. Here is the correctly defined kendo.bind method call. Please note, that the preferred way to bind a Mobile View is using the data-model attribute.

    Regards,
    Georgi Krustev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  8. Mike
    Mike avatar
    18 posts
    Member since:
    Jun 2011

    Posted 19 Jul in reply to Georgi Krustev Link to this post

    Your link to "the data-model attribute" is broken.

    Is it supposed to be linked here? http://docs.telerik.com/kendo-ui/api/javascript/data/model

    If so, can we see an example of the "correct" way to bind the switch control?

  9. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 20 Jul Link to this post

    Hello Mike,

    The "data-model" link was supposed to point the readers to the correct way to bind Mobile View:

    http://docs.telerik.com/kendo-ui/api/javascript/mobile/ui/view#configuration-model

    As to how a slider can be bound to MVVM model, then I would suggest you examine our online demo and the corresponding MVVM value binding documentation:

    http://docs.telerik.com/kendo-ui/framework/mvvm/bindings/value
    http://demos.telerik.com/kendo-ui/slider/mvvm

    Regards,
    Georgi Krustev
    Telerik by Progress
     
    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