yii2 active field template
Asked Answered
D

3

10

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?

Dislocation answered 6/11, 2014 at 9:27 Comment(0)
D
17

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>']
) ?>
Dortch answered 9/12, 2014 at 11:22 Comment(0)
D
4

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();
Deluna answered 8/9, 2016 at 6:57 Comment(0)
B
1
<?= $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

Byte answered 22/9, 2015 at 11:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.