简体   繁体   中英

Yii2 Progress Widget Clickable Fields

I am trying to make my page display a number of different progress widgets together to form a dynamic bigger progress bar. Each one of the widgets needs to be clickable to take the user to that respective stage. Here is what I have tried so far:

<?php
    $retVal = "";
    $stages = Phases::find()->asArray()->all();
    foreach($stages as $stage)
    {
        $percent = PrjApprovals::percentageComplete($model->id, $stage['phase']);
        echo $retVal = '<div style="float:left; padding-top: 20px;">' .
        Progress::widget
        ([
            'percent' => $percent,
            'label' => $stage['phase'],
            'attributes' => 
                function($model)
                {
                    $url = Url::to(['phases/' . $stage['phase'], 'id' => $model->id]);
                    return ['onclick' => "window.location.href='{$url}'"];
                },
         ]) . '</div>';
    }
?>

I need the link to not change any of the content in the progress widget but make it so that the current content is clickable. The link needs to send the user to whichever stage they clicked on and with that respective model id ($model->id).

I know "attributes" is not right, I've tried barOptions, options, rowOptions and everything else I can find. Still no luck.

The options attribute .. can contain all the html key for a tag .. so you can use class , id ... and href too .. and obviuosly onclick to .. but accept an array (with model value) and not (i think) an anonymous function, so you should form your option value content in your model ..

<?php
$retVal = "";
$stages = Phases::find()->asArray()->all();
foreach($stages as $stage)
{
    $percent = PrjApprovals::percentageComplete($model->id, $stage['phase']);
    echo $retVal = '<div style="float:left; padding-top: 20px;">' .
    Progress::widget
    ([
        'percent' => $percent,
        'label' => $stage['phase'],
        'options' => ['href' => 'your_url'], 
     ]) 
}
?>

or if you have a model attribute mystage_link you can use

     'options' => ['href' =>$model->mystage_link], 

Solved it!

$url = Url::to(['phases/' . $gate, 'id' => $model['id']]);

'options' => ['onclick' => "window.location.href='{$url}'"],

Thank you everyone!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM