问题
i have the following code in my view:
<?=Html::dropdownList('region',null,
ArrayHelper::map(Ethioregion::find()->all(),'region','region'),[
'prompt' => 'Select Region..','style'=>'width:200px',]) ?>
<?= Html::submitButton('Search', ['name' => 'dele','class' => 'btn btn-primary']) ?>
my code working well but I have one big problem. I select a region and click the search button, the result comes correctly, and 10 result is shown per page when I click the next page, it gives me false data, I notice this is due to the selected value on the dropdownlist is reset. I tried both making " Selected'=> true, and 'Selected'=>'selected', but it does not work. so how can I make the selected value on dropdownlist and checkboxlist will be selected after the page is loading? thanks
回答1:
It is very simple, you must pass integer $region_id
only:
<?=Html::dropdownList('region', $region_id,
ArrayHelper::map(Ethioregion::find()->all(),'region','region'),[
'prompt' => 'Select Region..','style'=>'width:200px',]) ?>
来源:https://stackoverflow.com/questions/53899049/how-to-keep-selected-value-on-yii2-htmldropddownlist