PDA

View Full Version : [resolved] Ext Msg Confirm change button text



dmassiani
27 Dec 2010, 3:14 AM
Hi,

How i can change the button text ? (yes and no)



handler: function(){
Ext.Msg.confirm("Etes vous sûr", "", function(e){if(e == 'yes'){
Ext.getCmp('main').setActiveItem(6);
}
});
}


thanks in advance.

Salva
29 Dec 2010, 4:17 AM
Hi dmassiani,

I don't know if it's the proper way, but this is how I've finally done it:



if(Ext.MessageBox) {
var MB = Ext.MessageBox;
Ext.apply(MB, {
YES: { text: 'Sí', itemId: 'yes', ui: 'action' }
});

Ext.apply(MB, {
YESNO: [Ext.MessageBox.NO, Ext.MessageBox.YES]
});
}

I just changed the 'Yes' button, as 'No' is the same in Spanish, but you could also change it. Have a look at lines 39875 - 39894 in sencha-touch-debug-w-comments.js (1.0.1) and you'll see the properties you have to override to change the default texts.

dmassiani
29 Dec 2010, 8:20 AM
yes that's done

i have do that :


var MB = Ext.MessageBox;
Ext.apply(MB, {
YES: { text: 'Oui', itemId: 'yes', ui: 'action' }
});
Ext.apply(MB, {
NO: { text: 'Non', itemId: 'no' }
});
Ext.apply(MB, {
YESNO: [Ext.MessageBox.NO, Ext.MessageBox.YES]
});


thank you

Salva
29 Dec 2010, 9:19 AM
If you want to make it shorter,


var MB = Ext.MessageBox;
Ext.apply(MB, {
YES: { text: 'Oui', itemId: 'yes', ui: 'action' },
NO: { text: 'Non', itemId: 'no' }
});
Ext.apply(MB, {
YESNO: [MB.NO, MB.YES]
});

Should also work. Only YESNO has to be applied after YES and NO have been assigned, as it references them and if you did it in the same "apply" method their values would still be the old ones.
Ext.MessageBox could also be shortened to MB in the second Ext.apply (I made the mistake when writing the example code).

dmassiani
29 Dec 2010, 11:32 PM
thanks you very much.
i appreciate your answer

alile
20 Dec 2012, 2:04 PM
I found this solution which I find to be more preferable: http://www.epiphanydigital.biz/2011/10/11/modify-a-sencha-touch-ext-msg-prompt-with-custom-buttons/



Ext.Msg.show({
title : 'Enter Email Address',
msg : null,
buttons : [{
itemId : 'ok',
text : 'Send',
ui : 'action'
},{
itemId : 'cancel',
text : 'Cancel'
}],
prompt : {
maxlength : 180,
autocapitalize : false },
fn : function(text,btn) { // do some stuff }
});

EmilMatei
11 Mar 2013, 11:45 AM
Ext.MessageBox.prompt() is using Ext.MessageBox object properties, like buttonText.

If you do something like this :

var promptBox = Ext.Msg;
promptBox.buttonText={
cancel: 'cancelText',
no: 'noText',
ok: 'okText',
yes: 'yesText'
};

If you call :
promptBox.prompt(title, message, callback)

OK and CANCEL buttons are displayed with their text label.

Tested in ExtJs 3.2

renatorro
3 Dec 2014, 11:35 AM
I think the proper way to do that is by overriding the default texts of MessageBox, just like the ExtJS's "ext-locale" package:



Ext.define("PIM.overrides.MessageBox", {
override: "Ext.MessageBox",
statics: {
OK : {text: 'OK', itemId: 'ok', ui: 'action'},
YES : {text: 'Sim', itemId: 'yes', ui: 'action'},
NO : {text: 'Não', itemId: 'no'},
CANCEL: {text: 'Cancelar', itemId: 'cancel'},

INFO : Ext.baseCSSPrefix + 'msgbox-info',
WARNING : Ext.baseCSSPrefix + 'msgbox-warning',
QUESTION: Ext.baseCSSPrefix + 'msgbox-question',
ERROR : Ext.baseCSSPrefix + 'msgbox-error',

OKCANCEL: [
{text: 'Cancelar', itemId: 'cancel'},
{text: 'OK', itemId: 'ok', ui : 'action'}
],
YESNOCANCEL: [
{text: 'Cancelar', itemId: 'cancel'},
{text: 'Não', itemId: 'no'},
{text: 'Sim', itemId: 'yes', ui: 'action'}
],
YESNO: [
{text: 'Não', itemId: 'no'},
{text: 'Sim', itemId: 'yes', ui: 'action'}
]
}
});