Hello, I’m using Kartik dependent dropdownlist, my ideia is to filter companies that a user is associated so I have 2 dropdownlists:
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($com, 'dot_com_id')->staticInput() ?>
<?= $form->field($com, 'dot_com_name')->staticInput() ?>
<?php echo $balance ?>
<?= $form->field($trade, 'dot_db_dots')->textInput(); ?>
<?= $form->field($rel, 'dot_wallet_id')->dropDownList(ArrayHelper::map(UserProfile::findBySql("Select * from dot_users_profiles where id !=" . Yii::$app->user->id)->all(), 'id', 'full_name'), ['prompt' => 'Select'])?>
<?= $form->field($trade, 'dot_trade_com_id')->widget(DepDrop::classname(), [
'pluginOptions' => [
'depends' => [ Html::getInputId($rel, 'dot_wallet_id'), // the id for cat attribute
Html::getInputId($com, 'dot_com_id')], // the id for subcat attribute],
'placeholder' => 'Select...',
'url' => Url::to(['load2'])
]
]);
?>
And this is my controller:
public function getUserCompanies2($userID, $com_id) {
$out = [];
$i = 0;
$dots = Dot::findBySql("SELECT `dot_dots_com_id`, SUM( `dot_dots_balance` ) AS balance, `dot_dots_datecreate` , `dot_dots_expiredate`
FROM dot_dots
WHERE dot_dots_wall_id =" . $userID . "
AND dot_dots_com_id !=" . $com_id . "
GROUP BY dot_dots_com_id")->asArray()->all();
for ($i = 0; $i < sizeof($dots); $i++) {
$company = Company::findOne($dots[$i]['dot_dots_com_id']);
$out[$i] = ['id' => $company->dot_com_id, 'name' => $company->dot_com_name];
}
return $out;
}
public function actionLoad2() {
$out = [];
if (isset($_POST['depdrop_parents'])) {
$ids = $_POST['depdrop_parents'];
$cat_id = empty($ids[0]) ? null : $ids[0];
$subcat_id = empty($ids[1]) ? null : $ids[1];
if ($cat_id != null) {
$out = self::getUserCompanies2($cat_id, $subcat_id);
echo Json::encode(['output' => $out, 'selected' => '']);
return;
}
}
echo Json::encode(['output' => '', 'selected' => '']);
}
Don’t know it’s not returning. It says Loading and don’t move…