Checkbox event not firing

2 posts, 0 answers
  1. Edward
    Edward avatar
    29 posts
    Member since:
    Aug 2014

    Posted 10 Sep 2014 Link to this post

    I can't seem to get the change event to fire. 

    Here's the code:

    <div class="k-edit-label">
        @(Html.LabelFor(model => model.IsAllDay))
    </div>
    <div data-container-for="isAllDay" id="is-all-day" class="k-edit-field">
        <input data-bind="checked: isAllDay" data-val="true" id="isAllDay" name="isAllDay" type="checkbox" />
    </div>

    I've tried:

    $(function () {
        $("#isAllDay").change(function () {
            alert("changed changed");
        });
    });

    and

    <div class="k-edit-label">
        @(Html.LabelFor(model => model.IsAllDay))
    </div>
    <div data-container-for="isAllDay" id="is-all-day" class="k-edit-field">
        <input data-bind="checked: isAllDay, events: { change: isAllDayChanged}" data-val="true" id="isAllDay" name="isAllDay" type="checkbox" />
    </div>
    function isAllDayChanged() {
        alert("changed");
    }

    What am I missing?
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 12 Sep 2014 Link to this post

    Hi Matt,


    From the provided information it seems that the reason for current behavior is that the handlers are not correctly placed in the code (not accessible in the checkbox scope). Please consider the following example which works as expected on our side:

    <div data-container-for="isAllDay" class="k-edit-field">
        <input id="isAllDay" name="isAllDay" type="checkbox" data-bind = "checked:isAllDay" />
    </div>
    <script>
        $(function () {
            /*use the edit event or place the handler inside the editor*/
            $("\\#isAllDay").change(function () {
                alert("changed changed");
            });
        });
    </script>

    Kind Regards,
    Vladimir Iliev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top