how to make yii2 generate two buttons in a modal on the footer side?

0

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();
        });

    });

});
    
asked by jeanpitx 12.10.2017 в 18:24
source

1 answer

1

With the following you have a modal with a title, a content and a footer with two buttons (One with your action to eliminate and the other with the option to cancel) ...

    <?php
    Modal::begin([
      'id'=>'modal-delete',
      'header' => 'Titulo',
      ]);
    ?>
      <h1>Mensaje de confirmacion u otro contenido</h1>

      <div class="modal-footer">
      <p class="pull-left">
        <br>
        <?php echo Html::a('Eliminar', ['controlador/accion'], ['class' => 'btn btn-danger']); ?>
        <button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-lg fa-times-circle"></i>&nbsp; Cancelar</button>
      </p>
      </div>

    <?php 
      Modal::end();
    ?>

In order for the footer to come out of another color you must add the following in the main.css

.modal-footer{
  background-color: #f5f5f5;
}
    
answered by 13.06.2018 / 22:55
source