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

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

    Posted 12 Sep 2012 Link to this post

    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/ 
  2. Petyo
    Admin
    Petyo avatar
    2438 posts

    Posted 12 Sep 2012 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Alex
    Alex avatar
    23 posts
    Member since:
    Aug 2012

    Posted 13 Sep 2012 Link to this post

    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.

  5. Answer
    Petyo
    Admin
    Petyo avatar
    2438 posts

    Posted 13 Sep 2012 Link to this post

    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!
  6. Alex
    Alex avatar
    23 posts
    Member since:
    Aug 2012

    Posted 13 Sep 2012 Link to this post

    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');
                });
        });
    };
Back to Top
Kendo UI is VS 2017 Ready