Answer the question
In order to leave comments, you need to log in
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(),
),
)
);
Answer the question
In order to leave comments, you need to log in
Try modifying the $category array itself before outputting. I'm not aware of its structure, but something like:$category[] = ['value'=>0, 'text'=>''];
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 questionAsk a Question
731 491 924 answers to any question