Html::activeDropDownList how to add title to <option>

I want to have a tooltip when I hover a <option> in <select>.

The above StackOver post says it may works if I put "title" within <option> tag.

I check out documentation for activeDropDownList (http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#activeDropDownList()-detail) but still dont understand how to put "title" inside <option> tag.

I expect to see:




<select name='report'>

    <option value="1" title="Test 1">Choice #1</option>

    <option value="2" title="Test 2 ">Choice #2</option>

</select>



Here is my code and i am so clueless




<?=

    Html::activeDropDownList($model, 'report_id', ArrayHelper::map($reports, 'id', 'name'), 

    ['id' => 'report-id', 'data-placeholder' => 'Select A Report', 'title' => 'My Test label' ])

?>




According with the documentation at:

http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#activeDropDownList()-detail

It should be:




<?=

    Html::activeDropDownList(

        $model, 

        'report_id', 

        ArrayHelper::map($reports, 'id', 'name'), 

        ['id' => 'report-id', 'data-placeholder' => 'Select A Report',

        

        'options' => ArrayHelper::map($reports, 'name', function($innerModel, $defaultValue) {

            return ['title' => $innerModel->name];

        }), 

          

        ])

?>

Your suggestion points me to the right direction. your code give me Notice error on $innerModel

I got it to




    Html::activeDropDownList($model, 'report_id', ArrayHelper::map($reports, 'id', 'name'), 

    ['id' => 'report-id', 'data-placeholder' => 'Select A Report', 

        'options' =>  [

            '13' => ['title' => 'Title #13'],

            '12' => ['title' => 'Title #12']

        ]

    ])



so i just need to tweak the ‘options’ to fit my needs.

Thanks alot.

Yes, but with your solution you have options values static, when they should be dynamic (if options decrease or increase) ?

It is just for demonstration, i probably create an array data.




<?php

$titleOptions = [];


foreach($titles as $title) {

    $titleOptions[$title->id] = ['title' => $title->getDescription()];

}

?>

<?=

    Html::activeDropDownList(

        $model, 

        'report_id', 

        ArrayHelper::map($reports, 'id', 'name'), 

        ['id' => 'report-id', 'data-placeholder' => 'Select A Report',

        

        'options' => $titleOptions 

          

        ])

?>



Thank you for suggestion. It works great