how to keep selected value on Yii2 html::dropddownlist?

老子叫甜甜 提交于 2019-12-20 07:48:42

问题


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',]) ?>
and submit button

 <?= 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!