Revision #239 has been created by rackycz on Oct 8, 2020, 2:06:33 PM with the memo:
Modal and ajax
« previous (#238) next (#240) »
Changes
Title
unchanged
Yii v2 snippet guide
Category
unchanged
Tutorials
Yii version
unchanged
2.0
Tags
unchanged
tutorial,beginner,yii2
Content
changed
[...]
]);
echo "<div id='modalContent'></div>";
yii\bootstrap\Modal::end();
$this->registerJs(
"$('a.openInModal').click(function(e){
e.preventDefault();// If you use $(document).on, it will handle also events on elements rendered by AJAX.
// $(document).on('click','a.openInModal',function(e){
// And if you use $('a.openInModal'), it will work only on standard elements
$('a.openInModal').click(function(e){
// Prevents the browsers default behaviour (such as opening a link)
// ... but does not stop the event from bubbling up the DOM
e.preventDefault();
// Prevents the event from bubbling up the DOM
// ... but does not stop the browsers default behaviour
// e.stopPropagation();
// Prevents other listeners of the same event from being called
// e.stopImmediatePropagation();
// Good idea is to set onclick='return false;' to the link if it is in a modal window
let title = $(this).attr('data-modal-titl');
if (title==undefined) { title = ''; }
$('#modalDialog1 #modalTitle').text(
'aaa'title);
$('#modalDialog1').modal('show')
.find('#modalContent')
.load($(this).attr('href'));
return false;
});",[...]