Change events for related fields

2 posts, 0 answers
  1. jmillar
    jmillar avatar
    35 posts
    Member since:
    Oct 2006

    Posted 17 Nov 2014 Link to this post

    Hi all;

    I'm working on a project that has a model with dependent fields.  As an example, consider a model with fields for both metric and imperial length (for my purpose, they both need to be writable fields).  So when one value changes, I need to change the other as well -- I'm using MVVM to bind both of these to a Kendo view.  My first attempt was to bind a function to the set event of each in the Kendo observable object, but I have a hunch that's going to lead to an infinite loop (changing metric, leading to changing imperial, leading to changing metric, etc.)  Am I going about this the wrong way?


        var oc = kendo.observable({
            MetricLength: 1,
            ImpLength: 3.28

        oc.bind("set", function(e) {
            if (e.field == "MetricLength") {
                oc.set("ImpLength",e.value * 3.28);
            if (e.field == "ImpLength") {
  2. Alexander Popov
    Alexander Popov avatar
    1445 posts

    Posted 19 Nov 2014 Link to this post

    Hi Jason,

    In the current scenario I would suggest using flags to avoid entering an infinite loop. Here is a small example how that could be done.

    Alexander Popov
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top