T
T
Turik-us2014-11-13 23:33:10
Yii
Turik-us, 2014-11-13 23:33:10

How to insert empty option in dropDownListGroup?

yii framework,
I display the form using yiibiooster.
The form has a select

echo $form->dropDownListGroup(
    $model,
    'parent',
    array(
        'widgetOptions' => array(
            'data' => $category,
            'htmlOptions' => array(),
        ),
    )
);

$category - array of options for slect
How can I print an empty option as well?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
EgorVorozhtsov, 2014-11-14
@EgorVorozhtsov

Try modifying the $category array itself before outputting. I'm not aware of its structure, but something like:
$category[] = ['value'=>0, 'text'=>''];

N
Nicholas, 2014-11-21
Sumrak @NikolasSumrak

Try passing empty=>' ' or 'propt'=> ' ' as an option

P
pavelblossom, 2015-04-30
@pavelblossom

I do so. Then, in the model, validation for a non-empty value needs to be done and that's it.

echo $form->dropDownListGroup(
            $model,
            'parent',
            [
                'widgetOptions' => [
                    'data'        => array_merge(array('0' =>'Choose parent'), $category),
                    'htmlOptions' => array(),
                ],
            ]
        );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question