How to overide a private method?
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);
}
})
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?
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
#If you have any other info about this subject , Please add it free.# |