PDA

View Full Version : How to override cancelEdit in Ext.Editor



zhaoshixuan
21 Nov 2011, 12:53 AM
Dears,
cancelEdit of Ext.Editor will reset the start value of component, if validation fails. I want to keep the wrong value and give users alert or sth in some scenarios. But I find no place can override this method.
Actually, I think I need remove them from this method.

var v = this.getValue();
this.setValue(this.startValue);
this.fireEvent("canceledit", this, v, this.startValue);
Could someone lend me a hand?
BTW, my ext version is 3.3. And this function is for column editor.
There is an example I wrote, it dosn't work
this.editor1 = function(){
var editor = new Ext.Editor(new Ext.form.TextField({
maxLength : 5
}));
editor.cancelEdit = function(remainVisible){
if(this.editing){
this.hideEdit(remainVisible);
}
}
return editor;
};
I set this editor to a column. The column still use cancelEdit in ext-all-debug.js

mitchellsimoens
21 Nov 2011, 8:36 AM
If you want to change cancelEdit you can do this easily:


Ext.override(Ext.Editor, {
cancelEdit : function(remainVisible){
if(this.editing){
var v = this.getValue();
//this.setValue(this.startValue);
this.hideEdit(remainVisible);
this.fireEvent("canceledit", this, v, this.startValue);
}
}
});

As you can see I commented out the setValue which may be of help to you. However, cancelEdit is also used when you press the Esc button so this would affect that as well. Also completeEdit uses it too.

zhaoshixuan
22 Nov 2011, 6:22 PM
If you want to change cancelEdit you can do this easily:


Ext.override(Ext.Editor, {
cancelEdit : function(remainVisible){
if(this.editing){
var v = this.getValue();
//this.setValue(this.startValue);
this.hideEdit(remainVisible);
this.fireEvent("canceledit", this, v, this.startValue);
}
}
});

As you can see I commented out the setValue which may be of help to you. However, cancelEdit is also used when you press the Esc button so this would affect that as well. Also completeEdit uses it too.
It works, but actually I found that I should override completeEdit of Editor.
I delete code about cancelEdit there.
Thanks for you kindness!