yii2 bootstrap modal hide show

12,862

Solution 1

For preventing closing when clicking on black area use:

'backdrop' => 'static',

There is another way of closing - by clicking Esc button. It can be prevented like that:

'keyboard' => false,

You should put these options under clientOptions section like that:

'clientOptions' => [
    ...
],

See this related question for details.

No need to write additional javascript for events to achieve that.

Solution 2

Use the following method:

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

For more details please refer this.

Share:
12,862
Vikram Pote
Author by

Vikram Pote

Xamarin developer. Love to code and try different technologies.

Updated on June 18, 2022

Comments

  • Vikram Pote
    Vikram Pote almost 2 years

    I am using yii2 bootstrap model to show some data on that and bootstrap model is close through two ways,

    1)on click of model close button.

    2)on click of that black area which is appeared in background like light-box.

    I already handle the close button event but unable to handle that black area click event. I don't want to close my model while click on that black area how should i do that.Please help me. Thanks in advance.

    My model

    <?php 
    Modal::begin([
        'header' => 'Student Info',
        'id' => 'stud-info',
        'closeButton' => ['id' => 'close-button'],      
        ]); 
    
        $form->field($model, 'StudName',
            [
            'options'=>['enableAjaxValidation' => false]
            ])->textInput();
    
     Modal::end();