M
M
Msklf2018-04-28 17:21:31
Yii
Msklf, 2018-04-28 17:21:31

How to set value for prompt dropdownlist in Yii2?

How to set your own value for the prompt value in the dropdown list:

<?= $form->field($model, 'table_id')->label('')->dropdownList(
            Table::find()->select(['row_name', 'id'])->indexBy('id')->column(),
            ['prompt' =>'Промпт',  'class'=>'', 'id'=>'', 'options' => [
        4 => ['data-image' => '', 'data-html-text'=>''], 
        6 => ['data-image' => '', 'data-html-text'=>''],
        9 => ['data-image' => '', 'data-html-text'=>''],
    ] ]);
        ?>

Actually Returns in html Didn't find a way how to set value in prompt. 'prompt' =>'Промпт',
<option value="">Промпт</option>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-04-28
@Msklf

You have already set options and if you want to set the data-* attribute, then it is done like this

[
   'prompt' => 'Select',
   'data' => [
      'text' => 'Text',
      'image' => 'Image'
   ]
]

or a little easier
[
  'prompt' => 'Select',
  'data-text' => 'Text',
  'data-image' => 'Image'
]

Well, for prompt you can use an array
'prompt' => [
    'text' => 'Select',
    'options' => [
        'value' => 'prompt',
        'class' => 'prompt-class',
        'selected' => 'selected'
    ]
]

It's all in the documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question