public function actionJudgeCategoryList()
{
$out = [];
if (isset($_POST['depdrop_parents'])) {
//$id = end($_POST['depdrop_parents']);
$parents = $_POST['depdrop_parents'];
if ($parents != null) {
$judge_id = $parents[0];
}
$judge_comitet_id = null;
if (!empty($_POST['depdrop_params'])) {
$params = $_POST['depdrop_params'];
$judge_comitet_id = $params[0]; // get the value of judge_id
}
$date_from = Appointment::getDateTo(Appointment::DATE_LAST_APP);
$list = JudgeComitet::find()->where(['judge_id'=>$judge_id])->all();
$selected = null;
if ($judge_id != null && count($list) > 0 ) {
$selected = '';
foreach ($list as $i => $model) {
if ($model->date_from >= $date_from) {
$comitet = Comitet::findOne($model->comitet_id);
$category = Category::findOne($model->category_id);
$out[] = ['id' => $model->id, 'name' => $model->id];
if ($i == 0) {
$selected = $judge_comitet_id;
}
}
}
// Shows how you can preselect a value
echo Json::encode(['output' => $out, 'selected'=>$selected]);
return;
}
}
echo Json::encode(['output' => '', 'selected'=>'']);
}
'params'=>[$model->judge_id],
$judge_id = null;
if (!empty($_POST['depdrop_params'])) {
$params = $_POST['depdrop_params'];
$judge_id = $params[0]; // get the value of judge_id
}
// Shows how you can preselect a value
echo Json::encode(['output' => $out, 'selected'=>Judge::findOne($judge_id)]);
'onchange' => '
$.post(
"'.Url::toRoute('ajax/list').'",
{id : $(this).val()},
function(data){
$("select#regions").html(data).attr("disabled", false)
}
)
'
........
$out[] = ['id' => $model->id, 'name' => $comitet->name.' ('.$category->name.')'];
........
echo Json::encode(['output' => $out, 'selected'=>$selected]);
, а не выбранную запись. Возможно придёться сделать разные action для выборки всех данных и одного при редактировании. Просто я думал здесь предусмотрено редактирование записи. Либо у меня что-то не то. Хотя делал всё по примеру из документации <?= $form->field($model, 'judge_comitet_id', ['options' => ['class' => 'col-sm-6']])->widget(Select2::classname(), [
'data' => ArrayHelper::map(Appointment::getJudgeWhere(), 'id', 'appInfoJudge'),
'language' => 'ru',
'options' => ['placeholder' => 'Выберите категорию...'],
//'disabled' => true,
'pluginOptions' => [
'allowClear' => true
],
]);?>
<?= $form->field($model, 'judge_comitet_id', ['options' => ['class' => 'col-sm-3']])->widget(DepDrop::classname(), [
'type'=>DepDrop::TYPE_SELECT2,
'data' => ArrayHelper::map(Appointment::getJudgeWhere(), 'id', 'appInfoJudge'),
'pluginOptions'=>[
'depends'=>['appointment-judge_id'],
'placeholder' => 'Выберите категорию...',
'url' => Url::to(['/appointment/judge-category-list']),
'loadingText' => 'Загрузка категорий...',
'initialize' => true,
'initDepends'=>['appointment-type_judge'],
]
]);?>