Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS 4 or 4.1 MessageBox Custom Buttons

Ext.MessageBox.show({
    title:'Messagebox Title',
    msg: 'Are you sure want to delete?',
    buttons: {yes: "Some Button 1",no: "Some Button 2",cancel: "Some Button 3"}
});

ExtJS 4 or 4.1 does not support this code. Buttons do not show.

like image 558
Ekrem OĞUL Avatar asked Sep 04 '12 12:09

Ekrem OĞUL


2 Answers

Just found out how to do this, hopefully it helps someone. As you can see you can handle the buttons however you want. Note that the framework only has 4 buttons by default and that is a limitation that won't be easily overcome. In the source there are multiple loops hard coded from 0 to < 4.

Ext.MessageBox.show({
    title:'Messagebox Title',
    msg: 'Are you sure want to delete?',
    buttonText: {yes: "Some Button 1",no: "Some Button 2",cancel: "Some Button 3"},
    fn: function(btn){
        console.debug('you clicked: ',btn); //you clicked:  yes
    }
});
like image 86
user1766719 Avatar answered Nov 12 '22 16:11

user1766719


You cannot do that inside the method show, since the buttons config in the method takes as an argument a number identifying the buttons to show. What you can do is to predefine your message box and then just show it.

 var win = Ext.create('Ext.window.MessageBox', {
     width:300,
     height: 100,
     buttons: [
      {text: 'My button 1'},{
        text: 'My button 2'}
    ]
});

win.show({
     title:'Messagebox Title',
     msg: 'Are you sure want to delete?',
    icon: Ext.Msg.QUESTION
});​
like image 4
nscrob Avatar answered Nov 12 '22 14:11

nscrob