I am using a Select2 widget:
<?php echo $form->field($model, 'id_person')->widget(
\common\widgets\Select2::classname(),
[
'items' => \yii\helpers\ArrayHelper::map(\app\models\Persons::find()->all(), 'id_person', 'name_person'),
'placeholder' => '',
'class' => 'form-control',
'options' => [
'id' => 'idPerson' // For jQuery.
]
]
)
?>
Then I use jQuery to disable it and set a value as I read in this StackOverflow question:
function($) {
$("#idPerson").prop("disabled", true)
.select2('data', {id: 1, a_key: 'John'});
});
It properly disabled the Select2 but the value is not set so the controller doesn't received the value.