Difference between #240 and #241 of
Yii v2 snippet guide

Revision #241 has been created by rackycz on Oct 8, 2020, 2:34:24 PM with the memo:

Modal and ajax
« previous (#240) next (#242) »

Changes

Title unchanged

Yii v2 snippet guide

Category unchanged

Tutorials

Yii version unchanged

2.0

Tags unchanged

tutorial,beginner,yii2

Content changed

[...]
'username',
'email:email',
['class' => 'yii\grid\ActionColumn',
'buttons' => [
'user_ajax_update_btn' => function ($url, $model, $key) {
return Html::a ( '<span class="glyphicon glyphicon-share"
 aria-hidden="true"></span> ', ['user/update', 'id' => $model->id], ['class' => 'openInMyModal', 'data-myModal-tTitle' => 'Some text']
);
},
[...]
// This section can be moved to "\views\layouts\main.php"
yii\bootstrap\Modal::begin([
'header' => '<span id="m
yModalTitle">Title</span>', 'id' => 'myModalDialog1', 'size' => 'modal-lg', ]); echo "<div id='myModalContent'></div>"; yii\bootstrap\Modal::end(); $this->registerJs( "// If you use $(document).on, it will handle also events on elements rendered by AJAX. // $(document).on('click','a.openInMyModal',function(e){ // And if you use $('a.openInMyModal'), it will work only on standard elements  // $('a.openInMyModal').click(function(e){

// Prevents the browsers default behaviour (such as opening a link)
[...]
// Good idea is to set onclick='return false;' to the link if it is in a modal window

let title = $(this).attr('data-m
yModal-tTitle'); if (title==undefined) { title = ''; } $('#myModalDialog1 #myModalTitle').text(title); $('#myModalDialog1').modal('show') .find('#myModalContent') .load($(this).attr('href')); return false; });", yii\web\View::POS_READY, 'myModalHandler'
);
?>
[...]
return "<script>"
. "$.pjax.reload({container:'#user-list-GridView'});"
. "$('#m
yModalDialog1').modal('hide');"
. "</script>";
}

return $this->redirect(['view', 'id' => $model->id]);
}
[...]
7 0
4 followers
Viewed: 255 127 times
Version: 2.0
Category: Tutorials
Written by: rackycz
Last updated by: rackycz
Created on: Sep 19, 2019
Last updated: 5 months ago
Update Article

Revisions

View all history