hello guys,
i have some problem when using checkboxlist. this checkboxlist was dependent with dropdownlist.
checkboxlist generate when i choose one value in dropdownlist.
then checkboxlist will generate by ID.
the problem is when i save the form, i cant get the value from the that generated checkboxlist.
this the code from view and my controller
- region view
<?= $form->field($model, 'cp_countrytarget')->dropDownList(
ArrayHelper::map(\app\models\Countries::find()->all(), 'countries_id', 'name'),
[
'prompt' => 'Select Country',
'class' => 'dependent-input form-control',
'onchange' => '$.get("index.php?r=tbcampaign/countries&id='.'"+$(this).val(), function(data) {
$("#tbcampaign-cp_statetarget").html(data);
});'
]); ?>
<?=
$form->field($model, 'cp_statetarget[]')->checkboxlist([],
[
//'onclick' => "$(this).val($('input:checkbox:checked').val()); ",
//'onclick' => "alert($('input[type=checkbox]').val()); ",
]);
?>
-region controller
public function actionCountries($id)
{
$states = States::find()->where(['country_id' => $id])->all();
foreach ($states as $state)
{
return Html::checkboxList('Tbcampaign[cp_citiestarget][]',[],ArrayHelper::map($states, 'name', 'name'), []);
}
but if i generate checkboxlist like this i can save the form normally to database, but thats not dynamically.
- view
<div class="container" style="overflow-y:scroll; width:auto; height:250px;">
<?php $datacities = ArrayHelper::map(\app\models\States::find()->all(), 'name', 'name');
?>
<?= $form->field($model, [cp_citiestarget][]')->checkboxList$datacities [
'separator' => '',
'itemOptions' => [
'class' => 'cities'
]
]);
?>
<?= $this->registerJs("jQuery('#checkAll').change(function(){jQuery('.cities').prop('disabled',this.checked?'checked':'');
})");?>
</div>
whats wrong with that my dynamically checkboxlist?
*sorry for my bad english
thankyou