Bootstrap tooltip not work
polinwei opened this issue · comments
I modify the code 'original-title' => Module::t('module', 'Click to change auth key')
in the view: _profile.php , I follow the index.php to want to show tooltip , but not work. Could you tell me why?
HTML:
[
'attribute' => 'auth_key',
'format' => 'raw',
'value' => function($data){
if ( $data->id == Yii::$app->user->identity->getId()){
$this->registerJs("$('#gen_auth_key_link_" . $data->id . "').click(handleAjaxLink);", \yii\web\View::POS_READY);
return Html::label($data->auth_key,'',[
'id' => 'auth_key_' . $data->id,
]) .' '.
Html::a('<span class="label label-warning">Generate</span>' , Url::to(['gen-authkey', 'id' => $data->id]) , [
'id' => 'gen_auth_key_link_' . $data->id,
'data' => [
'pjax' => 0,
'toggle' => 'tooltip',
'replace-id' => 'auth_key_' . $data->id,
'original-title' => Module::t('module', 'Click to change auth key'),
],
]);
}
return $data->auth_key;
}
],
Try this:
Html::a('<span class="label label-warning">Generate</span>' , Url::to(['gen-authkey', 'id' => $data->id]) , [
'id' => 'gen_auth_key_link_' . $data->id,
'title' => Module::t('module', 'Click to change auth key'),
'data' => [
'pjax' => 0
'toggle' => 'tooltip',
'replace-id' => 'auth_key_' . $data->id,
]
]);
or register the tooltip on the data-original-title:
The method: yii2-advanced-start/backend/web/js/dashboard.js
does not work.
$('[data-toggle="tooltip"]').tooltip();
Create a test link
To support the tooltip in the frontend do the following:
- Create js file:
/frontend/web/js/my_script.js
/**
* My scripts
*/
$(function () {
$('[data-toggle="tooltip"]').tooltip();
});
- Connect it to AppAsset.php
yii2-advanced-start/frontend/assets/AppAsset.php
Lines 33 to 35 in a151445
We check:
Done!
Another way to register the script in the current form:
View:
<?php
/* @var $this yii\web\View */
$this->registerJs("
$(function () {
$('[data-toggle=\"tooltip\"]').tooltip();
});
");
?>
<a href="#" data-toggle="tooltip" title="This title tooltip">Link</a>
or
<?php
/* @var $this yii\web\View */
$this->registerJs(new \yii\web\JsExpression("
$(function () {
$('[data-toggle=\"tooltip\"]').tooltip();
});
"), yii\web\View::POS_END);
?>
<a href="#" data-toggle="tooltip" title="This title tooltip">Link</a>
Done!