Skip to content

Add Custom Buttons

Coackroach edited this page Jan 19, 2020 · 2 revisions

You can add the custom buttons to your form wizard if you like. you have to collect all the buttons inside an array and pass it to the toolbarExtraButtons option wrapping inside the new \yii\web\JsExpression() call. See below how to add a single button to your formwizard.

use buttflattery\formwizard\FormWizard;
$js = <<< JS
    var mybutton = $( '<button id="new"></button>' ).text( 'New Button' )
    .addClass( 'btn btn-warning' ).on("click",function(e){
        e.preventDefault();
        alert("hello");
    });
\JS;
$this->registerJs($js, yii\web\View::POS_READY);

echo FormWizard::widget([
    'toolbarExtraButtons' => new \yii\web\JsExpression('[mybutton]'),
    'steps' => [
        [
            'model' => $shootsModel,
            'title' => 'My Shoots',
            'description' => 'Add your shoots',
            'formInfoText' => 'Fill all fields'
        ],
        [
            'model' => $shootTagModel,
            'title' => 'Shoot Tags',
            'description' => 'Add your shoots',
            'formInfoText' => 'Fill all fields'
        ],
    ]
]);
Clone this wiki locally