PDA

View Full Version : MessageBox buttons custom text



Compilerrr
25 Feb 2012, 10:55 AM
Maybe i'm doing something wrong but

Ext.MessageBox.buttonText = {
ok : "Alright",
cancel : "Nooo",
yes : "Yeap",
no : "Noooo"
};
Ext.MessageBox.confirm('bla-bla?', 'bla-bla-bla?', callback);

doesn't work for me.

For me solution is:

Ext.MessageBox.msgButtons.ok.text = 'OK';
Ext.MessageBox.msgButtons.cancel.text = '??????';
Ext.MessageBox.msgButtons.yes.text = '??';
Ext.MessageBox.msgButtons.no.text = '???';
Ext.MessageBox.confirm('bla-bla?', 'bla-bla-bla?', callback);


Anyone has the same problem?

P.S. Here http://docs.sencha.com/ext-js/4-0/#!/api/Ext.window.MessageBox
written that MessageBox is under window package but it is actually just Ext.MessageBox. Is this an error?

vietits
25 Feb 2012, 5:53 PM
Ext.MessageBox is a singleton instance of Ext.window.MessageBox. It's created when the Ext.window.MessagBox is loaded. If you want to use this instance and want to change its button labels, you should do as you did.


Ext.MessageBox.msgButtons.ok.text = 'OK';
Ext.MessageBox.msgButtons.cancel.text = '??????';
Ext.MessageBox.msgButtons.yes.text = '??';
Ext.MessageBox.msgButtons.no.text = '???';
Ext.MessageBox.confirm('bla-bla?', 'bla-bla-bla?', callback);

If you want to change button labels for all instances of custom message box, you should do as follow:


Ext.window.MessageBox.prototype.buttonText = {
ok : "Alright",
cancel : "Nooo",
yes : "Yeap",
no : "Noooo"
};
...
var msgBox = Ext.create('Ext.window.MessageBox');
msgBox.confirm('bla-bla?', 'bla-bla-bla?', callback);

If you want to change button labels of a specific instance of custom message box, you should do as follow:


var msgBox = Ext.create('Ext.window.MessageBox',{
buttonText: {
ok : "Alright",
cancel : "Nooo",
yes : "Yeap",
no : "Noooo"
}
});
msgBox.confirm('bla-bla?', 'bla-bla-bla?', callback);

Compilerrr
25 Feb 2012, 10:55 PM
Thank you for your answer.
Solutions that I found on forum doesn't work.
Maybe they do for earlier versions. So now we have it for 4.0 :)

alile
12 May 2013, 9:42 AM
In 2.2 at least, this does not work. The buttons are directly attached to Ext.MessageBox, and i was not able to find a more direct way to set them than the below.



Ext.MessageBox.OK.text = "my OK content"


so i set up an external strings object and iterated through it:



MessageBox:
{
OK: 'OK',
CANCEL: 'Cancel',
YES: 'Yes',
NO: 'NO'
},

// above assigned to strings

for(var i in strings)
{
Ext.MessageBox[i].text = strings[i];
}