Yii2 bootstrap modal hide show

I am using yii2 bootstrap model to show some data about this and bootstrap model is close in two ways,

1) by pressing the button to close the model.

2) when you click that black area that appears in the background, like a light window.

I am already handling the close button event but cannot handle the black area click event. I don't want to close my model when I click on this black area, how should I do this. Please help me. Thanks in advance.

My model

    'header' => 'Student Info',
    'id' => 'stud-info',
    'closeButton' => ['id' => 'close-button'],      

    $form->field($model, 'StudName',
        'options'=>['enableAjaxValidation' => false]




source to share

2 answers

To prevent closing when clicking on the black area use:

'backdrop' => 'static',


There is another way to close it by pressing a button Esc

. This can be prevented as follows:

'keyboard' => false,


You must put these options in the clientOptions section :

'clientOptions' => [


See this related question for details .

You don't need to write additional event javascript to achieve this.



Use the following method:

$('#myModal').on('hidden.bs.modal', function (e) {
  // do something...


See this for details .



All Articles