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

Detect whether switch is 'On' or 'Off'

6 Answers 981 Views
Switch (Mobile)
This is a migrated thread and some comments may be shown as answers.
Damien
Top achievements
Rank 1
Damien asked on 07 Feb 2013, 12:44 AM
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.



6 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 08 Feb 2013, 08:45 AM
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!
0
Gerardo
Top achievements
Rank 1
answered on 13 Jun 2013, 09:10 PM
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>
0
Alexander Valchev
Telerik team
answered on 14 Jun 2013, 07:18 AM
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!
0
Dina
Top achievements
Rank 1
answered on 15 May 2017, 02:14 PM

How to get switch state outside change event?

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

 

what next?

0
Misho
Telerik team
answered on 16 May 2017, 12:50 PM
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.
0
John
Top achievements
Rank 1
Veteran
Iron
answered on 14 Apr 2022, 06:43 PM

the switch updates the internal checkbox as it operates.  You could just do something like this (jquery)
$("#switch").prop("checked")

 

Tags
Switch (Mobile)
Asked by
Damien
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Gerardo
Top achievements
Rank 1
Dina
Top achievements
Rank 1
Misho
Telerik team
John
Top achievements
Rank 1
Veteran
Iron
Share this question
or