Detect whether switch is 'On' or 'Off'

6 posts, 0 answers
  1. Damien
    Damien avatar
    8 posts
    Member since:
    Jan 2013

    Posted 06 Feb 2013 Link to this post

    Hi Alexander/Telrik -

    I would like to know if there is a way to see if the switch is either checked or unchecked?

    Basically something like: ON || OFF

    if switch.OFF:then run this.function()
    If switch.NOT.OFF run that.function();


    I had a look at your examples on the demo page but only show a console.log("Checked?Unchecked")
    Which toggies with the switch but doesn't allow binding a specific event to the status of a switch.

    Thanks in advance.



  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2886 posts

    Posted 08 Feb 2013 Link to this post

    Hi Damien,

    Switch widget has a check method which allows you to get its state. Also it have a change event that fires when state of the widget changes.

    Regards,
    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Gerardo
    Gerardo avatar
    1 posts
    Member since:
    Jun 2013

    Posted 13 Jun 2013 Link to this post

    Hi,
    I'm using the documentation you mentioned and I cannot get manage to make it work, I tried it in my current project and it didn't work, I also tried in a blank project with no luck either.

    I copy here the documentation of your event, and hope to get an answer soon.

    Thanks

    <input type="checkbox" id="switch" data-role="switch" />

    <script>
    $("#switch").data("kendoMobileSwitch").bind("change", function(e) {
    console.log(e.checked); // true or false
    }
    </script>
  4. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2886 posts

    Posted 14 Jun 2013 Link to this post

    Hi Gerardo,

    I prepared a small example where everything seems to work as expected.

    Please compare your implementation with the one presented in the sample.

    Regards,
    Alexander Valchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. Dima
    Dima avatar
    45 posts
    Member since:
    Feb 2012

    Posted 15 May in reply to Alexander Valchev Link to this post

    How to get switch state outside change event?

    var myswitch = $("#myswitch ").data("kendoMobileSwitch");

     

    what next?

  6. Misho
    Admin
    Misho avatar
    148 posts

    Posted 16 May Link to this post

    Hi,
    You could use the Check() method of the mobile switch component to get the checked state.
    http://dojo.telerik.com/@parvanov/AkoXe

    Regards,
    Misho
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top