I have a Modal that by clicking on delete, it shows a warning dialog box to eliminate, the problem is that I have a single button and I would like to add another one that says cancel, likewise I would like to add a color to the modal header, but I do not know how to do it, someone could help me, I tried to do it in the following way
'footer' => [Html::a('Aceptar', '/', ['class' => 'btn btn-danger', 'id' => 'delete-confirm','data-method' => 'post',]),
Html::a('Aceptar', '/', ['class' => 'btn btn-danger', 'id' => 'delete-confirm','data-method' => 'post',])
],
but it shows the following error: 'Array to string conversion'.
My code: I have a footer which contains the following in yii2 within the index view:
<?php Modal::begin([
'header' => '<h3 class="modal-title"></h3>',
'id' => 'modal-delete',
'footer' => Html::a('Aceptar', '/', ['class' => 'btn btn-danger', 'id' => 'delete-confirm','data-method' => 'post',]),
]); ?>
<?='<h5><center>¿Está seguro que desea eliminar este item?</h5></center>'; ?>
<?php Modal::end(); ?>
likewise in the bottom of the same view, I call that Modal through the delete button
'delete'=>function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', '', [
'class' => 'btn btn-xs btn-danger popup-modal',
'data-toggle' => 'popupModal',
'data-target' => '#popupModal',
//'data-id' => $model->id_producto,
//'data-name' => $model->nombre,
'data-url' => $url,
]);
},
my javascript to work this contains the following
$(function() {
$('.popup-modal').click(function(e) {
e.preventDefault();
var modal = $('#modal-delete').modal('show');
modal.find('.modal-body').load($('.modal-dialog'));
var that = $(this);
//var id = that.data('id');
//var name = that.data('name');
var url = that.data('url');
//modal.find('.modal-title').text('Eliminar el item \"' + name + '\"');
modal.find('.modal-title').text('¿Está seguro?');
document.getElementById("delete-confirm").href=url;
$('#delete-confirm').click(function(e) {
e.preventDefault();
window.location = url;
});
$('#cancel-confirm').click(function(e) {
this.hide();
});
});
});