<?= $form->field($model, 'id_education_stage')->dropDownList(
\yii\helpers\ArrayHelper::map(\app\models\EducationStage::find()->all(), 'id', 'name'),
) ?>
$this->registerJs("
$(function(){
alert('test')
})
", View::POS_END);
<?= $form->field($model, 'id_education_stage')->dropDownList(
\yii\helpers\ArrayHelper::map(\app\models\EducationStage::find()->all(), 'id', 'name'),
['prompt' => 'Выберите уровень образования',
'onchange' => '
$.post(
"'.Url::toRoute('ajax/list-degree').'",
{id : $(this).val()},
function(data){
$("select#degree").html(data).attr("disabled", false)
}
)
']
) ?>
<?= $form->field($model, 'id_scientific_degree')->dropDownList(
\yii\helpers\ArrayHelper::map(\app\models\ScientificDegree::find()->all(), 'id', 'name'),
[
'id' => 'degree',
'disabled' => $model->isNewRecord ? 'disabled' : false,
]
)?>
public function actionListDegree()
{
if(\Yii::$app->request->isAjax)
{
$id = (int)\Yii::$app->request->post('id');
$degrees = ScientificDegree::find()->all();
$this->option = '<option value="0">Выберите ученую степень</option>';
foreach($degrees as $degree){
$this->option .= '<option value="'.$degree->id.'">'.$degree->name.'</option>';
}
}
return $this->option;
}
я прописала свойство 'style' => 'display:none', поле исчезло, но label висит.
типа бакалавр, магистр и т.д. есть только у высшего образования
$this->registerJs("
$(function(){
alert('test')
})
", View::POS_END);
<?= $form->field($model, 'role')->dropDownList(ArrayHelper::map(Yii::$app->authManager->getRoles(),
'name', 'description'
),
[
'id' => 'roles'
]
)
?>
<?= $form->field($model, 'status', ['options' =>['style' => 'display:none']])->dropDownList(UsersAdmin::getStatusesArray(), ['prompt' => 'Select']) ?>
<?php
$this->registerJs("
$('#roles').on('change', function(){
if($(this).val() == 1){
$(this).parent('.form-group').next().show()
}
else{
$(this).parent('.form-group').next().hide()
}
})
", View::POS_END);
?>
<?= $form->field($model, 'id_education_stage')->dropDownList(
\yii\helpers\ArrayHelper::map(\app\models\EducationStage::find()->all(), 'id', 'name'),
['prompt' => 'Выберите уровень образования',
'id' => 'stage']
) ?>
<?= $form->field($model, 'id_scientific_degree', ['options' =>['style' => 'display:none']])->dropDownList(
\yii\helpers\ArrayHelper::map(\app\models\ScientificDegree::find()->all(), 'id', 'name'),
[
'prompt' => 'Выберите',
]
)?>
<?php
$this->registerJs("
$('#stage').on('change', function(){
if($(this).val() == 1){
$(this).parent('.form-group').next().show()
}
else{
$(this).parent('.form-group').next().hide()
}
})
", View::POS_END);
?>