Subscribing to changes?

6 posts, 1 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 22 May 2012 Link to this post

    I need a checkbox bound to a bool in my model...however on click I need to persist that change to a webservice.

    data-bind="checked: AvailableToHamilton, click: shareWith"

    So in this case I need the checkbox to show the state of the model, then the click event I need to send the value and then call a function to update a count based on the model.

    What's HAPPENING though it seems is this
    1) Checked
    2) Ajax Call
    3) Ajax Complete
    4) Function Runs to get count (checks bool state)
    5) Bool state changed

    So I know this because if I set a timeout on step 4
    success: function (e) {
        setTimeout(function(){
            viewModel.getTotalCapacity();
        }, 100);
    }

    ...then the count updates okay...

    So if I could subscribe to a change on the property (somehow) then the function could run AFTER it changes.

    Steve
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 23 May 2012 Link to this post

    Hi,

     The click event of the checkbox is raised before its value is updated. You can try using the change event instead.

    Regards,
    Atanas Korchev
    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. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 23 May 2012 Link to this post

    OH!  I didn't even know that was an event to hook into...I don't see it anywhere in the documentation\demos

    I will try it, thanks
  5. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 23 May 2012 Link to this post

    ...seems to work!

    Thanks again
  6. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 23 May 2012 Link to this post

    Hi,

    By "change" event I meant the DOM "change" event of the checkbox. You should use the events binding to handle it.

    Greetings,
    Atanas Korchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  7. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 23 May 2012 Link to this post

    Ahh is that what it is, okay thanks (I noticed data-bind="change: " didn't work so I tried that next.
Back to Top
Kendo UI is VS 2017 Ready