Trying to obtain the same effect, a password filed prompt, I saw that I cannot override the MessageBox being a singleton (does not have a prototype).
So I've changed (expanded) a little bit the Ext.MessageBox function to have support for a passwordPrompt as well.
It would be nice to be able to override this function as well in order not to mess the original code, or to be able to pass the configuration of the input field instead of hide / show textinput / textarea / and now password fields.
I will post it here maybe somebody else will find it useful:
1. added passwordEl variable in the variable list in the MessageBox header;
PHP Code:
var dlg, opt, mask, waitTimer;
var bodyEl, msgEl, textboxEl, textareaEl, passwordEl, progressBar, pp, iconEl, spacerEl;
var buttons, activeTextEl, bwidth, iconCls = '';
2. Added an input type="password" after the textarea in getDialog method, and now it looks like:
PHP Code:
bodyEl = dlg.body.createChild({
html:'<div class="ext-mb-icon"></div><div class="ext-mb-content"><span class="ext-mb-text"></span><br /><div class="ext-mb-fix-cursor"><input type="text" class="ext-mb-input" /><textarea class="ext-mb-textarea"></textarea><input type="password" class="ext-mb-input" /></div></div>'
});
3. In the same method, below textareaEl.enableDisplayMode(); I've added:
PHP Code:
passwordEl = Ext.get(contentEl.childNodes[2].childNodes[2]);
passwordEl.enableDisplayMode();
passwordEl.addKeyListener([10,13], function(){
if(dlg.isVisible() && opt && opt.buttons){
if(opt.buttons.ok){
handleButton("ok");
}else if(opt.buttons.yes){
handleButton("yes");
}
}
});
4. Changed show method, the condition for prompt to:
PHP Code:
if(opt.prompt){
if(opt.multiline){
textboxEl.hide();
passwordEl.hide();
textareaEl.show();
textareaEl.setHeight(typeof opt.multiline == "number" ?
opt.multiline : this.defaultTextHeight);
activeTextEl = textareaEl;
}else if(opt.password){
passwordEl.show();
textboxEl.hide();
textareaEl.hide();
activeTextEl = passwordEl;
}else{
textboxEl.show();
textareaEl.hide();
passwordEl.hide();
}
}else{
textboxEl.hide();
textareaEl.hide();
passwordEl.hide();
}
5. After prompt method, I've added passwordPrompt method, which is exactly the same like prompt one, only has a password: true extra option. I didn't changed the options of prompt method to keep it working as well in the rest of the framework.
PHP Code:
passwordPrompt : function(title, msg, fn, scope, multiline, value){
this.show({
title : title,
msg : msg,
password: true,
buttons: this.OKCANCEL,
fn: fn,
minWidth:250,
scope : scope,
prompt:true,
multiline: multiline,
value: value
});
return this;
},
And in the code you can use it like: Ext.Msg.passwordPrompt({...usual config...});