I have a problem that’s driving me mad. I have two Select2-Dropdowns showing employees, one for dayshift, the other for nightshift. The employee selected for dayshift should be removed from the nightshift dropdown and vice versa. I managed to refresh the nightshift dropdown when an employee is selected in the dayshift dropdown, but when I select an employee in the nightshift dropdown he isn’t removed from the dayshift dropdown…
here’s the snippet from the _form.php:
<?= $form->field($model, 'customer_id')->widget(Select2::classname(), [
'options'=>['id'=>'customer-id','class'=>'customer-id shift-name'],
'disabled' => !$create_jn,
'data' => ArrayHelper::map(customer::find()->where(['active_yn' => 1])->orderBy(['name'=>SORT_ASC])->all(),'customer_id','name')
]); ?>
<?=
$form->field($model, 'site_id')->widget(DepDrop::classname(), [
'options'=>['id'=>'site-id','class'=>'site-id shift-name'],
'disabled' => $disable_yn,
'type' => DepDrop::TYPE_SELECT2,
'pluginOptions'=>[
'depends'=>['cutomer-id'],
'placeholder'=>'Please choose',
'url'=>Url::to(['/site/customer-site']),
// 'initialize'=>true,
]]);
?>
<?= $form->field($model, 'site_employee_id')->widget(DepDrop::classname(), [
'options'=>['id'=>'site-employee-id'],
'disabled' => $disable_yn,
'type' => DepDrop::TYPE_SELECT2,
'pluginOptions'=>[
'depends'=>['customer-id'],
'placeholder'=>'Please choose',
'url'=>Url::to(['/site/customer']),
'params' => ['site-employee-night-id'],
// 'initialize'=>true,
]
]); ?>
<?= $form->field($model, 'bst_leiter_nacht_id')->widget(DepDrop::classname(), [
'options'=>['id'=>'site-employee-night-id'],
'disabled' => $disable_yn,
'type' => DepDrop::TYPE_SELECT2,
'pluginOptions'=>[
'depends'=>['customer-id','site-employee-id'],
'placeholder'=>'Please choose',
'url'=>Url::to(['/site/customer-night']),
'params' => ['site-employee-id'],
'initialize'=>true,
]
]); ?>
and here’s the controller:
public function actionCustomer() {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$out=array();
if (isset($_POST['depdrop_parents'])) {
$parents = $_POST['depdrop_parents'];
if (isset($_POST['depdrop_params'])) {
$params = $_POST['depdrop_params'];
if ($parents != null) {
$customer_id = $parents[0];
if($params != null) {
$site_employee_night_id = $params[0];
$out= \frontend\models\Employee::find()
->where(['customer_id'=>$customer_id])
->andWhere(['<>','employee_id', $site_employee_night_id])
->select(['employee_id as id','CONCAT(firstname," ",lastname) as name'])
->orderBy('lastname')->asArray()->all();
return ['output'=>$out, 'selected'=>''];
}
}
}
}
return ['output'=>'', 'selected'=>''];
}
public function actionCustomerNight() {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$out=array();
if (isset($_POST['depdrop_parents'])) {
$parents = $_POST['depdrop_parents'];
if (isset($_POST['depdrop_params'])) {
$params = $_POST['depdrop_params'];
if ($parents != null) {
$customer_id = $parents[0];
if($params != null) {
$site_employee_id = $params[0];
$out= \frontend\models\Employee::find()
->where(['customer_id'=>$customer_id])
->andWhere(['<>','employee_id', $site_employee_id])
->select(['employee_id as id','CONCAT(firstname," ",lastname) as name'])
->orderBy('lastname')->asArray()->all();
return ['output'=>$out, 'selected'=>''];
}
}
}
}
return ['output'=>'', 'selected'=>''];
}
Any help, tips, hints would be highly appreciated.