Yii2 dropDownList Default value

Yii2 dropDownList Default value

Content Index :

Yii2 dropDownList Default value
Tag : development , By : LinnheCreative
Date : November 24 2020, 03:01 PM

I hope this helps . In yii2 I have a dropdownlist: , I got it! The solutions is to write in the controller:
public function actionCreate()


No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Yii2 dropdownlist WITHOUT $model

Tag : php , By : CHeMoTaCTiC
Date : March 29 2020, 07:55 AM
Hope this helps I have searched the web far and wide for a solution to this problem. I already know the Yii2 dropdown way is this: , You can also use
<?= Html::dropDownList('s_id', null,
      ArrayHelper::map(Standard::find()->all(), 's_id', 'name')) ?>

Yii2 dropdownList select default option

Tag : development , By : Nicholas Hunter
Date : March 29 2020, 07:55 AM
may help you . Finally solved with an unbelievable change. Just changed the first letter of selected to capital ('selected' should be 'Selected'). Here is the code:
<?= $form->field($model, 'cat_id')->dropDownList(
->where(['is_deleted' => 'no'])->all(),'id','title')
,['options' => [$_GET['cat_id'] => ['Selected'=>'selected']]
, 'prompt' => ' -- Select Category --']) ?>

how can I get a value, not key from dropDownList Yii2

Tag : yii2 , By : Adil
Date : March 29 2020, 07:55 AM
I hope this helps you . Use the same value for key and value
in this sample country have code and name and the mao give you key value
echo $form->field($model, 'name')->dropDownList($listData, ['prompt'=>'Choose...']);

Get same values in DropDownList yii2

Tag : development , By : Sergio Rudenko
Date : March 29 2020, 07:55 AM
To fix the issue you can do The problem lies in your code. In your actionCreate() you have created three model objects of the same type DevisReduction.
$modelDevisReduction1 = new DevisReduction();
$modelDevisReduction2 = new DevisReduction();
$modelDevisReduction3 = new DevisReduction();
<?= $form->field($modelDevisReduction1, 'idReduction')->dropDownList( ArrayHelper::map(Reduction::find()->all(),'idReduction','libelle'), ['prompt'=>'Sélectionner la Reduction','id'=>'DevisReductionType-1'] )->label(false); ?>

<?= $form->field($modelDevisReduction2, 'idReduction')->dropDownList( ArrayHelper::map(Reduction::find()->all(),'idReduction','libelle'), ['prompt'=>'Sélectionner la Reduction','id'=>'DevisReductionType-2'] )->label(false); ?>

<?= $form->field($modelDevisReduction3, 'idReduction')->dropDownList( ArrayHelper::map(Reduction::find()->all(),'idReduction','libelle'), ['prompt'=>'Sélectionner la Reduction','id'=>'DevisReductionType-3'] )->label(false); ?>

class DevisReductionForm extends yii\base\Model {

    public $idReduction1;
    public $idReduction2;
    public $idReduction3;
    public $taux1;
    public $taux2;
    public $taux3;

     * @inheritdoc
    public function rules() {
        $rules = [
                    [['idReduction1', 'idReduction1', 'idReduction1', 'taux1', 'taux2', 'taux3'], 'required'],

        return array_merge($rules, parent::rules());

public function actionCreate()
    //create object of custom form model DevisReductionForm given above
    $modelDeviceReduction = new DevisReductionForm ();

    if ($modelDeviceReduction->load(Yii::$app->request->post())
         $modelDevisReduction1 = new DevisReduction();
         $modelDevisReduction2 = new DevisReduction();
         $modelDevisReduction3 = new DevisReduction();

         $modelDevisReduction1->idReduction =  $modelDeviceReduction->idReduction1
         $modelDevisReduction2->idReduction =  $modelDeviceReduction->idReduction2
         $modelDevisReduction3->idReduction =  $modelDeviceReduction->idReduction3

         $modelDevisReduction1->taux = $modelDeviceReduction->taux1
         $modelDevisReduction2->taux = $modelDeviceReduction->taux2
         $modelDevisReduction3->taux = $modelDeviceReduction->taux3
          //write other codes

        return $this->render('create', [
            'modelDeviceReduction ' => $modelDeviceReduction ,

/* Reduction 1 */
<?= $form->field($modelDeviceReduction, 'idReduction1')->dropDownList( ArrayHelper::map(Reduction::find()->all(),'idReduction','libelle'), ['prompt'=>'Sélectionner la Reduction','id'=>'DevisReductionType-1'] )->label(false); ?>

<?=  $form->field($modelDeviceReduction,'taux1')->textInput(['maxlength' => true,'id'=>'DevisReductionTaux-1'])->label(false); ?>

/* Reduction 2 */
<?= $form->field($modelDeviceReduction, 'idReduction2')->dropDownList( ArrayHelper::map(Reduction::find()->all(),'idReduction','libelle'), ['prompt'=>'Sélectionner la Reduction','id'=>'DevisReductionType-2'] )->label(false); ?>

<?=  $form->field($modelDeviceReduction,'taux2')->textInput(['maxlength' => true,'id'=>'DevisReductionTaux-2'])->label(false); ?>

/* Reduction 3 */
<?= $form->field($modelDeviceReduction, 'idReduction3')->dropDownList( ArrayHelper::map(Reduction::find()->all(),'idReduction','libelle'), ['prompt'=>'Sélectionner la Reduction','id'=>'DevisReductionType-3'] )->label(false); ?>

<?=  $form->field($modelDeviceReduction,'taux3')->textInput(['maxlength' => true,'id'=>'DevisReductionTaux-3'])->label(false); ?>

Capture a value from a dropdownlist where the display dropdownlist is not default

Tag : chash , By : Topher Cyll
Date : March 29 2020, 07:55 AM
hope this fix your issue You're repopulating the DropDownList for every postback and reloading the page, hence the SelectedValue property value may be different from the posted value. Just put a check against IsPostBack to prevent repopulating DropDownList data on postback:
protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)
        List<ListItem> items = new List<ListItem>();

        for (int i = 0; i < 5; i++)
           items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));

        ddldate.DataSource = items;
        ddldate.Items[0].Selected = true;
Related Posts Related QUESTIONS :
  • What is a good barebones CMS or framework?
  • What's the Developer Express equivalent of System.Windows.Forms.LinkButton?
  • Is it acceptable for invalid XHTML?
  • Anyone soloing using fogbugz?
  • Using MBUnit in TeamCity
  • How to setup a crontab to execute at specific time
  • Linking two Office documents
  • How can I detect if a browser is blocking a popup?
  • Apply filter to t-foreach
  • Lotus Notes convert formula to agent
  • Problem with configuration of odoo for working with pycharm
  • Unexpected number of arguments when calling EM_JS function
  • What does the function state_fidelity() do in Qiskit?
  • Azure function with IoT Hub trigger get send device
  • Cluster similar words using word2vec
  • Add elements into an array then find distinct,
  • Angular8 - error TS2304: Cannot find name
  • Manually polling streams in future implementation
  • How do you perform receipt validation for Android on Xamarin Forms
  • What is the rule behind instruction count in Intel PIN?
  • How to draw some text when click a button in wxWidgets?
  • Restrict entity types in Spacy NER
  • How to animate CN1 Slider progress on load
  • Issue with bwa mem process not running on all output files from previous process
  • Delete videos from playlist using YouTube API
  • How to restart the Hyperledger Composer Playground locally
  • How to configure email alerts in Zabbix Server?
  • Simulator is not working for smart home action with all configured session
  • How parse data using join on Objection.js
  • Assign an array to a property in a Chapel Class
  • Netlogo: How can I obtain the accumulate value in Netlogo?
  • How to populate datasource for listview using api response in react native?
  • Why does gmail API when using history.list method send message ids without the field what action has been preformed on t
  • How to run an append query in ms access vba as part of a transaction
  • Wrong dates shown in Jekyll-based blog
  • How to concatenate two document lists in a webMethods flow service?
  • How to properly set up a site map addition in a customization project
  • IBM Content Collector error calling external Web Service
  • Is (0*1*)* equal to (0 | 1)*?
  • How do I configure phpMyAdmin to start with a blank sql query from the SQL tab?
  • "Objects are not valid as a React child" Redux error when conditionally connecting a component?
  • Displacy results are not showing
  • Strapi / Graphql. What am i doing wrong?
  • How to add Search bar for django template?
  • lookup in presto using single column against a range in lookup table
  • How can you stop videos being stolen on website?
  • Can't code substitution happen in Hybrid Flow?
  • Removed widget remains on parent
  • setup saga middleware with redux-starter-kit's configureStore()
  • How to get cookies from response of scrapy splash
  • I need to do a firebase stream and not a Http Get
  • Unable to compile node-runtime
  • SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause'
  • How to extract only the number from a variable
  • disable linter in DAML studio
  • RxJS: How to set exhaustMap concurrent?
  • How to remove perforce (p4) on Ubuntu
  • How do they know mean and std, the input value of transforms.Normalize
  • Why this type is not an Interface?
  • SugarCRM Rest API set_relationship between Contacts and Documents
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com