We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

How to set selected in a HTML Select Tag with VIewHelper

Hi,

Im triing to preselect a Select Tag in Volt.

What I get so far:

 {{ select('langId', langs, 'using': ['id', 'name'], 'useEmpty': false,'ng-model':"orderProp") }}

I will no emtpy option. But the generated Code looks like this:

<select id="langId" name="langId" ng-model="orderProp" class="ng-pristine ng-valid">
    **<option value="? undefined:undefined ?"></option>**
    <option value="1">English</option>
</select>

IN the Docs i found nothing at: https://docs.phalcon.io/en/1.2.6/reference/volt.html#using-tag-helpers or here: https://docs.phalcon.io/en/1.2.6/reference/tags.html#making-select-boxes

Can please anyone help me?

Thanks.



300
Accepted
answer
edited Mar '14

try using $this->tag->setDefault('langId', '1'); ('langId' as name of your tag and '1' as value you want selected by default) in your controller action

Thaaanks digitronac!