zrk4939 / yii2-depdrop
The dependent dropdown widget for the Yii framework 2
Installs: 205
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:yii2-extension
This package is auto-updated.
Last update: 2025-03-28 23:38:57 UTC
README
A Dependent DropDown widget for the Yii2 framework
Installation
Add
"zrk4939/yii2-depdrop": "@dev"
to the require section of your composer.json
file and execute composer update
.
Usage
Widget
<?php echo $form->field($model, 'attribute')->widget(\zrk4939\widgets\depdrop\DepDrop::className(), [ 'placeholder' => 'Выбрать из списка...', 'depends' => ['id-dependent-field'], 'url' => \yii\helpers\Url::to(['/ajax/get', 'selected' => $model->getAttribute('attribute')]), ]) ?>
Controller
<?php public function actionGet() { Yii::$app->response->format = Response::FORMAT_JSON; $result = [ 'output' => [], 'selected' => Yii::$app->request->get('selected') ]; if (Yii::$app->request->isPost) { $post = Yii::$app->request->post('depdrop_all_params'); $query = SomeModel::find() ->andWhere(['attribute' => $post['attribute']]); foreach ($query->all() as $model) { $result['output'][] = [ 'id' => $model->getAttribute('id'), 'name' => $model->getAttribute('name'), ]; } } return $result; } ?>