Yii2 materialize checkbox and radio button not working
manosl24 opened this issue · 6 comments
Dear Macgyer,
Yii2 with mateirialize how to add checkbox and radio button field.I added checbox list but single checkbox how to add using materialize.Can you please help me..
Hi @manosl24,
as Materialize required checkboxes to not be enclosed by labels (as Yii renders as default), you need to set the $encloseByLabel
property to false.
See ActiveField and Materialize docs.
Example:
<?= $form->field($yourModel, 'attribute')->checkbox([], false) ?>
The first param of checkbox()
is the options array, the second param is $encloseByLabel
.
I will check the Materialize docs and will integrate an automatic option for $encloseByLabel
in a future release.
Cheers
Hi Macgyer,
Thanks for your response, i used<?= $form->field($yourModel, 'attribute')->checkbox([], false) ?>
this code.
Example:
It display in
<label for="idname">Active</label> <input type="checkbox" id="idname" />
but materialize checkbox displaying only below format
<input type="checkbox" id="idname"/><label for="idname">Active</label>
I am new to YII2, please can you help me how to display this type for checkbox template
Show me the whole view code where you create your form.
Best put it in a Gist and post the Gist link here.
Hi Macgyer,
Below mentioned the view code link.
https://gist.github.com/manosl24/460e023142086e1551cdf45304774acc
@manosl24, just as I assumed: you are not using yii2-materializecss ActiveForm but the Yii2 default ActiveForm widget.
use yii\widgets\ActiveForm; <-- needs to be replaced with yii2-materializecss ActiveForm
/* @var $this yii\web\View */
/* @var $form yii\widgets\ActiveForm */ <-- needs to be replaced with yii2-materializecss ActiveForm
?>
<div class="settings-form">
<?php $form = ActiveForm::begin(); ?> <-- needs to be replaced with yii2-materializecss ActiveForm
Thanks macgyer,i used both materialize and bootstrap so only i am not using..but now working fine..thanks a lot...