9

It seems template for checkbox in sample yii2 project doesn't not apply correctly

<?= $form->field($model, 'rememberMe', [
    'template' => "<div class=\"col-lg-offset-1 col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>",
])->checkbox() ?>

what's wrong here?

Herokiller
  • 2,891
  • 5
  • 32
  • 50

3 Answers3

15

You need to pass template like in this example

<?= $form->field($model, 'rememberMe')
->checkbox(
['template' => '<div class="form-group">{input}<label class="control-label">{label}</label></div>']
) ?>
ustmaestro
  • 1,233
  • 12
  • 20
3

Sad, that people add - to this great answer. This works great!

But you have to switch \yii\widget\ActiveForm class to \yii\bootstrap\ActiveForm

So:

\yii\bootstrap\ActiveForm:beginForm();

echo $form->field($model, 'terms_condition',['checkboxTemplate'=>"<div class=\"checkbox\">\n{input}
{beginLabel}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n</div>"])->checkbox(['value'=>true])

\yii\bootstrap\ActiveForm:endForm();
Brampage
  • 6,014
  • 4
  • 33
  • 47
Arturs Smirnovs
  • 163
  • 2
  • 6
0
<?= $form->field($model, 'terms_condition',['checkboxTemplate'=>"<div class=\"checkbox\">\n{input}
{beginLabel}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n</div>"])->checkbox(['value'=>true]) ?> 

use this code

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143