php - Yii2 delete confirmation modal -
i'm trying make delete confirmation modal yii2. have grid view action button deletes item of gridview.
when user clicks on button, popup modal shows , cannot id of item must deleted.
here code of gridview (only action button):
'buttons' => [ 'view' => function ($url, $model) { return html::a('', $url, ['class' => 'btn btn-success btn-xs glyphicon glyphicon-eye-open']); }, 'edit' => function ($url, $model) { if (yii::$app->user->getidgroupe() != 1) { return html::a(''); } return html::a('', $url, ['class' => 'btn btn-warning btn-xs glyphicon glyphicon-pencil']); }, 'delete' => function ($url, $model) { return html::a('', $url, ['class' => 'btn btn-danger btn-xs glyphicon glyphicon-trash', 'data-toggle' => 'modal', 'data-target' => '#modal', 'data-id' => $model->idressource, 'id' => 'popupmodal']); }, ], 'urlcreator' => function ($action, $model, $key, $index) { if ($action == 'view') { $url = url::to(['/ressource/view', 'id' => $model->idressource]); } else if ($action == 'edit') { $url = url::to(['/ressource/edit', 'id' => $model->idressource]); } else { $url = '#'; } return $url; },
then modal :
<?php $url = url::to(['ressource/delete']); ?> <?php modal::begin([ 'header' => '<h2 class="modal-title"></h2>', 'id' => 'modal-delete', 'footer' => html::a('supprimer', $url, ['class' => 'btn btn-danger']), ]); ?> <?= 'etes vous sur de vouloir supprimer la ressource ...'; ?> <?php modal::end(); ?>
and javascript :
<?php $this->registerjs("$(function() { $('#popupmodal').click(function(e) { e.preventdefault(); $('#modal-delete').modal('show').find('.modal-body') .load($('.modal-dialog')); var modal = $(this); var triggered = $(e.relatedtarget); var id = triggered.data('id'); $('.modal-title').text('supprimer la ressource ' + id); }); });"); ?>
and problem can't id of item , need when build $url because action 'actiondelete' need id of item.
hope clear , you'll able me ! thanks
php buttons:
'delete' => function ($url, $model) { return html::a('', $url, [ 'class' => '... popup-modal', 'data-toggle' => 'modal', 'data-target' => '#modal', 'data-id' => $model->idressource, 'id' => 'popupmodal-'. $model->idressource ]); },
js:
<?php $this->registerjs("$(function() { $('.popup-modal').click(function(e) { e.preventdefault(); var modal = $('#modal-delete').modal('show'); modal.find('.modal-body').load($('.modal-dialog')); var = $(this); var id = that.data('id'); modal.find('.modal-title').text('supprimer la ressource ' + id); }); });"); ?>
Comments
Post a Comment