Dominus77 / yii2-advanced-start

Yii2 Start Project Advanced Template

Home Page:https://dominus77.github.io/yii2-advanced-start/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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?

tooltip

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:

$('[data-toggle="tooltip"]').tooltip();

The method: yii2-advanced-start/backend/web/js/dashboard.js does not work.

$('[data-toggle="tooltip"]').tooltip();

Create a test link

<a href="#" data-toggle="tooltip" title="This title tooltip">Link</a>

2018-01-18_115133

To support the tooltip in the frontend do the following:

  1. Create js file: /frontend/web/js/my_script.js
/**
 * My scripts
 */
$(function () {
    $('[data-toggle="tooltip"]').tooltip();
});
  1. Connect it to AppAsset.php
    public $js = [
    'js/my_script.js'
    ];

We check:

2018-01-18_115238

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!