This is a migrated thread and some comments may be shown as answers.

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

1 Answer 109 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Brian Roth
Top achievements
Rank 1
Brian Roth asked on 04 Feb 2016, 07:02 PM

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.
        }
    }
},

1 Answer, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 09 Feb 2016, 08:40 AM

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!
 
Tags
MVVM
Asked by
Brian Roth
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or