Model class sets dirty = true even if set event is cancelled

2 posts, 1 answers
  1. Brian Roth
    Brian Roth avatar
    136 posts
    Member since:
    Oct 2005

    Posted 04 Feb Link to this post

    When calling set() on a kendo Model object, the 'dirty' field appears to be set to true even if the set is cancelled from the "set" event. See http://dojo.telerik.com/UMOVU for an example of this behavior.

    After a little research, I found that the kendo.data.Model.set() function is setting dirty = true before calling ObservableObject.set():

    set: function(field, value, initiator) {
        var that = this;
     
        if (that.editable(field)) {
            value = that._parse(field, value);
     
            if (!equal(value, that.get(field))) {
                that.dirty = true;
                ObservableObject.fn.set.call(that, field, value, initiator);
            }
        }
    },

    The problem could be fixed by doing something like this instead:

    set: function(field, value, initiator) {
        var that = this;
      
        if (that.editable(field)) {
            value = that._parse(field, value);
      
            if (!equal(value, that.get(field))) {
                // ObservableObject.set() should return a value indicating whether or not the default was prevented.
                if(!ObservableObject.fn.set.call(that, field, value, initiator))
                    that.dirty = true; // Only set dirty = true if the value was actually modified.
            }
        }
    },

  2. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 09 Feb Link to this post

    Hello Brian,

     

    Thank you for the feedback we will update the reference implementation to revert dirty state back to its original value if set event is prevented. The change should be available with next internal build.

     

    Regards,
    Nikolay Rusev
    Telerik
     
    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
Back to Top