H
H
hollanditkzn2017-07-24 12:09:11
JavaScript
hollanditkzn, 2017-07-24 12:09:11

Why doesn't my select2 event fire?

I do not have an event when clicking on the button, who can tell me what's wrong?

<?= $form->field($client, 'phone')->widget(Select2::className(), [
                    'data' => ArrayHelper::map(Client::find()->all(), 'id', 'phone', 'fio'),
                    'options' => ['placeholder' => 'Введите номер телефона'],
                    'pluginOptions' => [
                        'allowClear' => true,
                        'language' => [
                            'noResults' => new JsExpression('function () { return "<button type=\"button\" class=\"btn btn-primary btn-xs createClient\" value=\"'.\yii\helpers\Url::to(['client/create']).'\">Добавить клиента</button>"; }'),
                        ],
                        'escapeMarkup' => new JsExpression('function (markup) {
        return markup;
    }')
                    ],
            ])?>

js
$('.createClient').click(function(){
            console.log('Нажата')
        });

And I look through the debug, there are no errors, and the tag itself is displayed normally
Add client

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-07-24
@hollanditkzn

1. make sure that the click is on createClient. What he is and he is 1, etc.
2. try like this

$(body).on('click','.createClient',function(){
            console.log('Нажата');
        });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question