How set atributte on individual option of select

Notice: This thread is very old.
Member | 106

Hi again,

My questions is how can i set attribute with Form:setAttribute() method an option of select box

the next html code is generate by

$form->addSelect('parent_id', 'Recurso Padre:', $recursos, 15)->setAttribute('class', 'form-control');
<select name="parent_id" size="15" class="form-control" id="frm-crearEditar-parent_id">
<option value="0"></option>
<option value="1">Permiso Acl</option>
<option value="2">-- Sub de Acl Permiso</option>
<option value="3">---- Sub de sub de Acl Permiso</option>
<option value="4"> Acl Permiso 2</option>
<option value="5" selected>-- Sub de Acl Permiso2</option>
<option value="10">---- Nuevo recurso</option>

is there any way to add a " disabled " attribute to an option tag from Present class??

<option value="3" disabled >---- Sub de sub de Acl Permiso</option>


Last edited by alnux (2014-05-30 19:28)

Member | 106

I found a solution and share you

$arr = array(
    'item' => Nette\Utils\Html::el('option')->value('item')->setHtml('popisek'),
    'item2' => Nette\Utils\Html::el('option')->value('item2')->setHtml('popisek')->disabled(TRUE),

$form->addSelect('select', 'select', $arr)
// případně

thanks to Aurielle from link

Moderator | 1364

Unfortunately, this is something “view” part of application should take care of. Sadly there is probably no better way in Nette.