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

Switch does not fire "change" event to correspondent <input>

4 Answers 379 Views
Switch (Mobile)
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 12 Sep 2012, 02:42 PM
Hi again!
For me it is an issue, if switch widget should "replace" checkbox on my iPad, it should also fire "changed" event.
Fiddle:
http://jsfiddle.net/GewUa/14/ 

4 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 12 Sep 2012, 03:07 PM
Hi Alex,

Programmatically checking an HTML checkbox does not trigger its change event - check this fiddle:

http://jsfiddle.net/7WVqL/135/ 

Regards,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alex
Top achievements
Rank 1
answered on 13 Sep 2012, 09:40 AM
Of course it's true, but as I said, I see switch widget as a replacement of chekcbox and thus, if my application should do something on change I expect triggering change event.

Trying to fire this event by myself I found (maybe) another issue in your implementation. I tried to bind on "kendoMobileSwitch" change event, as described in documentation, but there is no "kendoMobileSwitch" data in input. Here is fiddle:

http://jsfiddle.net/GewUa/24/ 

I read the data with "kendoMobileSwitch" key and it is undefined! Do I something wrong?

In my application I have 4 switches, and only first one has this data, I could not explain this.
Please help.

0
Accepted
Petyo
Telerik team
answered on 13 Sep 2012, 10:31 AM
Hi Alex,

You can do that workaround in the view init event handler. The application (and its widgets) are not initialized immediately. 

Regards,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alex
Top achievements
Rank 1
answered on 13 Sep 2012, 10:56 AM
Thanks, thats worked for me. The reason, that first switch data was present, and another not, just simple : first switch was on the first view, and another on another views, and as I understood, view initialized just before showing.

Here is a sample to make switch fire change event to input:
var kendoMobileViewInit = function(e){
    $(e.view.element).find('.my-switch-class').each(function(){
        var switchData = $(this).data("kendoMobileSwitch");
        if(switchData)
            switchData.bind("change", function(e) {
                $(this.element).trigger('change');
            });
    });
};
Tags
Switch (Mobile)
Asked by
Alex
Top achievements
Rank 1
Answers by
Petyo
Telerik team
Alex
Top achievements
Rank 1
Share this question
or