1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    18
    Vote Rating
    0
    zhaoshixuan is on a distinguished road

      0  

    Thumbs up How to override cancelEdit in Ext.Editor

    How to override cancelEdit in Ext.Editor


    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

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,639
    Vote Rating
    817
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    If you want to change cancelEdit you can do this easily:

    Code:
    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.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    18
    Vote Rating
    0
    zhaoshixuan is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    If you want to change cancelEdit you can do this easily:

    Code:
    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!

Thread Participants: 1

Tags for this Thread