How to overide a private method?

  • I know I am not supposed to override a private method, but I need to! I want to override the handleButton() method of the Ext.MessageBox class. I have tried everything and it is driving me nuts! Can anyone help?


    Ext.override(Ext.MessageBox, function(){

    var handleButton = function(button){
    console.log('I am overridden!!!');
    };


    })


    and I have tried:



    Ext.override(Ext.MessageBox, {

    handleButton:function(button){
    console.log('I am overridden!!!');
    };


    })


    I AM able to override the non-private methods, and I am doing so in order to add validation to the prompt window. My code, looks is below, but I need to catch the click on the OK button to enforce the validation:


    Ext.app.validatedMessageBox = function() {
    var F = function(){};
    F.prototype = Ext.MessageBox;
    var o = function(){};
    o.prototype = new F();
    o.superclass = F.prototype;

    Ext.override(o, function(){
    var dlg, opt, mask, waitTimer;
    var bodyEl, msgEl, textboxEl, textareaEl,textfield, progressBar, pp, iconEl, spacerEl;
    var buttons, activeTextEl, bwidth, iconCls = '';



    return {
    getDialog : function() {
    console.log('Running getDialog');
    var d = o.superclass.getDialog.apply(this, arguments);
    textboxEl = Ext.DomQuery.select('input[type=text]',d.getEl().dom);
    textfield = new Ext.form.TextField({applyTo:textboxEl[0].id, allowBlank: false,inputType:'password',msgTarget:'qtip'});
    return d;
    },

    show: function(options){
    o.superclass.show.call(this, options);

    if(options.validator) {
    textfield.validator = options.validator;
    }else{
    textfield.validator = undefined;
    }
    },



    prompt : function(title, msg, fn, scope, validator, multiline, value){

    this.show({
    title : title,
    msg : msg,
    buttons: this.OKCANCEL,
    fn: fn,
    minWidth:250,
    scope : scope,
    prompt:true,
    multiline: multiline,
    value: value,
    validator:validator
    });
    return this;
    }

    };
    }());
    return new o();
    }();


    // render a button to test the validation in the prompt window

    btn = new Ext.Button({

    renderTo:'btn',
    text:'test',
    scope:this,
    handler:function(){
    Ext.app.validatedMessageBox.prompt('New Project', 'Please enter the new Project Folder Name:', function(){},this, function(text){return 'You already have a project with that name'},false);

    }
    })


  • I'm trying to override that method so that if the validation is not passed, the error is shown and the window does not get closed. I successfully added the ability to pass in a validation function, but the ok button still function as normal...


  • anyObj.override({
    aMethodToOverride : function() {
    // logic here.

    }

    });


    i think the problem may be that Ext.MessageBox is a singleton, not a class that is newly instantiated.

    Why are you trying to override the Ext.MessageBox? Why not just setup a callback for the OK button?


  • Hi,

    It doesn't matter how you try, you are never going to be able to override it - if you look at the definition...:


    Ext.MessageBox = function(){
    ...
    // private
    var handleButton = function(button){
    if(dlg.isVisible()){
    dlg.hide();
    Ext.callback(opt.fn, opt.scopewindow, [button, activeTextEl.dom.value], 1);
    }
    };


    ..you'll see that it's private and can only be accessed within the scope of Ext.MessageBox


  • I tried that code, and I get an error "Ext.MessageBox.override is not a function"







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about How to overide a private method? , Please add it free.

    15 March 2010 | cameltoepants.com | edit