A
A
Andrey2018-03-27 15:22:27
JavaScript
Andrey, 2018-03-27 15:22:27

Modal window, jquery doesn't accept id. Where is the mistake?

I have a grid table with a column

[
                        'class' => 'yii\grid\ActionColumn',
                        'template' => '{select}',
                        'buttons' => [
                            'select' => function($url){
                                return Html::a('<span class="glyphicon glyphicon-share" style="color:#228B22"></span>',$url, [
                                    'title' => 'Выбрать пункт приема',
                                    'class' => 'select',
                                    'data-toggle' => 'modal',
                                    'data-target' => 'unload'
                                ]);
                            }
                        ]
                    ]

The modal itself is standard from bootstrap.
spoiler
<div class="modal fade" id="unload" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h2 class="modal-title" id="exampleModalLabel">Пункт приема</h2>
                </div>
                <div class="modal-body">
                    <p>....</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-success">Save changes</button>
                    <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

And actually js:
<?php $this->registerJs(
    "
    $('.select').on('click', function(){
            var data = $(this).data();
        $('#unload').modal('show');
        $('#unload').find('.modal-title').text('id:' + data.key);
    });
    "
); ?>

The problem is that in the modal id: undefined. If the code is changed to everything works. Where am I doing it wrong?
$('.grid-view tbody tr').on('click', function()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-03-27
@DronTat

if you have already specified 'data-toggle' => 'modal', then why are you processing the click again. She does it twice. Perhaps this is the problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question