PDA

View Full Version : isDirty() function override



AJAIN32
17 Aug 2014, 11:06 PM
Hi,

I am using isDirty() function for different components of sencha extjs. now i have a situation where i have to treat lower case/upper case letters in the same way.

By default - if i change a field value of a component from "Value" to "value" then isDirty returns true, but now i need to check only value without case sensative check (like - for me isDirty() should return false in this case).

How can i achieve this.

Thanks,
Ankit

StuartAshworth
20 Aug 2014, 2:30 AM
You will need to override the 'set' method of the Model class which determines whether a field should become dirty or not.

Perhaps you could wrap the following snippet (taken from the 'set' method) in an if statement using a more 'loose' version of the isEqual method that is implemented in this class and only perform the change tracking if they are completely different.

http://docs.sencha.com/extjs/4.2.2/source/Model.html#Ext-data-Model-method-set





...
if(!me.isCaseInsensitiveEqual(currentValue, value){

(modifiedFieldNames || (modifiedFieldNames = [])).push(name);


if (field && field.persist) {
if (modified.hasOwnProperty(name)) {
if (me.isEqual(modified[name], value)) {
// The original value in me.modified equals the new value, so
// the field is no longer modified:
delete modified[name];


// We might have removed the last modified field, so check to
// see if there are any modified fields remaining and correct
// me.dirty:
me.dirty = false;
for (key in modified) {
if (modified.hasOwnProperty(key)){
me.dirty = true;
break;
}
}
}
} else {
me.dirty = true;
modified[name] = currentValue;
}
}

}
...

AJAIN32
26 Aug 2014, 1:18 AM
Thanks for reply,

I did it by checking each field manually as in some situation i need isDirty function as well.

But your approach is correct.

Thanks
Ankit