jamesdoe
jamesdoe

Reputation: 35

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.

Upvotes: 3

Views: 304

Answers (2)

jamesdoe
jamesdoe

Reputation: 35

Solved it!

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

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

Thank you everyone!

Upvotes: 0

ScaisEdge
ScaisEdge

Reputation: 133360

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], 

Upvotes: 1

Related Questions