Yii check box in dropdown menu

I am developing an application using the Yii framework. I need from a drop down list with checkboxes as the values โ€‹โ€‹of this list. I searched for this but found nothing. Can someone help me with this task?

+4
source share
3 answers

Here is a link to the Yii extension that does exactly what you want!

Yii Framework Extension: echmultiselect

In addition, there are other Yii extensions for feature rich features that are also quite interesting! You can also take a look at them!

Yii Framework Extension: Select2

Yii Framework Extension: emuliselect

+4
source

You can do it like this (in this example, your model should have a public $ availableLanguages โ€‹โ€‹field):

 <?= $yourActiveForm->field($model, 'availableLanguages', ['template' => " <div class='dropdown'> <button class='btn btn-default dropdown-toggle' data-toggle='dropdown' type='button'> <span>Select languages</span> <span class='caret'></span> </button> {input} </div>"])->checkboxList( [ 'FR'=>'France', 'DE'=>'Germany' ], [ 'tag' => 'ul', 'class' => 'dropdown-menu', 'item' => function ($index, $label, $name, $checked, $value) { return '<li>' . Html::checkbox($name, $checked, [ 'value' => $value, 'label' => Html::encode($label), ]) . '</li>'; } ]); ?> 
+2
source

You can create a simple text box, and when the user clicks, you will see a list of checkboxes

 <div id="listOfDays"> <span><?php echo Yii::t('frontend','CHOOSE_DAY'); ?> </span> </div> <div id="itemslistOfDays" style="display:none;position:absolute;z-index:10;background-color:white; width:300px"> <?php echo $form->checkBoxList($model, 'freq_details', array( '1'=>Yii::t('frontend','MONDAY'), '2'=>Yii::t('frontend','TUESDAY'), '3'=>Yii::t('frontend','WEDNESDAY'), '4'=>Yii::t('frontend','THURSDAY'), '5'=>Yii::t('frontend','FRIDAY'), '6'=>Yii::t('frontend','SATURDAY'), '7'=>Yii::t('frontend','SUNDAY'), )); ?> </div> 

You will need to write javascript or jquery to hide, show and link click event

0
source

All Articles