How do I add a Label Hint to Kartik DetailView

家住魔仙堡 提交于 2020-01-06 02:55:06

问题


I'm using Kartik DetailView and would like to have a hint appear when the user hovers over the label (like the GII forms). I've tried the following, but it does not work.

 $attributes = [
    [   'attribute'=>'name',
        'inputWidth'=>'50%',
    ],
    [   'attribute'=>'round_precision',
        'hint' => 'Specify the number of decimal digits after the decimal to round to.  Use a negative value to round the integer part of the number to the number of digits before the decimal. A value of 1 will round 1.855 to 1.7, and a value of -2 will round 1.855 1.86.  A value of -1 will round 17.6 to 18, and a value of -2 will round 17.6 to 20.',
        'inputWidth'=>'10%',
    ],
];

How do I get Gii-like hints in the Kartik DetailView Widget?


回答1:


It appears GII is just using Bootstrap Popovers. I followed the instructions on http://www.yiiframework.com/wiki/664/activating-bootstrap-3-tooltips-popover-for-your-yii-site/ and then began creating labels with help popovers.

I created the following function to render the label.

 /**
 * Create a help popover to be shown on an input form.
 * @param $label string The label to display for the input.
 * @param $help string The help text to display.
 * @return string
 */
public static function renderLabelHelp($label, $help) {
    return Html::tag('span', $label, [
        'data-toggle'=>'popover',
        'data-trigger' => 'click hover',
        'data-placement' => 'auto right',
        'data-html' => 'true',    // allow html tags
        'data-title'=> 'Field Help',
        'data-content'=>$help,
        'style'=>'text-decoration: underline; cursor:help;'
    ]);
}

Then I call the function with something like this.

<?= Html::label(MyHelpers::renderLabelHelp(
    $model->getAttributeLabel('round_precision'),
    'Specify the number of decimal digits after the decimal to round to.<br>Use a negative value to round the integer part of the number to the number of digits before the decimal.<br>A value of 1 will round 1.855 to 1.7, and a value of -2 will round 1.855 1.86.  A value of -1 will round 17.6 to 18, and a value of -2 will round 17.6 to 20.'
) ?>


来源:https://stackoverflow.com/questions/36858916/how-do-i-add-a-label-hint-to-kartik-detailview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!