2013-08-28 2 views
0

У меня есть MessageBox, сконфигурированный как этотПредотвратить MessageBox от закрытия

Ext.MessageBox.show({ 
buttons:Ext.MessageBox.OKCANCEL, 
prompt:true, 
buttonText:{ok:"Button1",cancel:"Button2"}, 
fn:function(btn, text, cBoxes){ 
    if(btn=='ok'){ 
    // do not close 
    // return false does not help 
    } 
} 
}); 

Я не знаю, как предотвратить его от закрытия на кнопку мыши. В частности, я не хочу закрывать его, когда пользователь нажимает кнопку «ok». Я видел переопределения в Интернете, но не знаю, как использовать свойства кнопок. Наверное, для этой задачи должно быть очень простое решение.

ответ

1

Вы должны использовать обычный window, над которым вы будете иметь полный контроль.

В вашем случае, это было бы что-то вроде этого:

Ext.widget('window', { 
    autoShow: true 
    ,closable: false 
    ,modal: true 
    ,title: "My window" 
    ,defaults: { 
     margin: 5 
    } 
    // you can obviously compose the items you want; an input field 
    // is what you get with the prompt window 
    ,items: [{ 
     xtype: 'textfield' 
     ,itemId: 'inputField' 
    }] 
    ,buttons: [{ 
     text: "Button1" 
     ,handler: function(button) { 
      // here's how to get a ref to the window (for closing) 
      var win = button.up('window'), 
       // here's the value of the field 
       input = win.down('#inputField').getValue(); 

      // you can close the window if you want, or not 
      if (!Ext.isEmpty(input)) { 
       win.close(); 
      } 
     } 
    },{ 
     text: "Button2" 
     ,handler: function() { 
      // ... 
     } 
    }] 
}); 
Смежные вопросы