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

How to access custom data attributes in a Switch's data-change function

1 Answer 299 Views
Switch (Mobile)
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 17 Jan 2013, 07:24 PM
I've seen various comments on best practice for doing this, but nothing definitive (that I've found) on the proper way to do this.

Given this:

<input data-role="switch" data-change="switchChangedHandler" data-subscriptionId="10" id="switch1"/>
<input data-role="switch" data-change="switchChangedHandler" data-subscriptionId="9" id="switch2"/>
<input data-role="switch" data-change="switchChangedHandler" data-subscriptionId="8" id="switch3"/>
How best to access subscriptionId in the handler function?
function switchChangedHandler(e) {
 
     // I've seen this in a forum example but is it really the best way?
    var subscriptionId = e.sender.element.context.dataset.subscriptionId;
 
     // How to best get it?
 
}
somehow the solution shown doesn't seem like the "Kendo" way.

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 21 Jan 2013, 12:48 PM
Hello Peter,

I suggest to use the data method of jQuery. Here is an example:
var id = e.sender.element.data("subscriptionid");

For convenience I created a small example (please watch the console) using this approach in action.
I hope this will help.

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!
Tags
Switch (Mobile)
Asked by
Peter
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or