2

I need to add a few attributes (f.e. disabled and selected) to the first option in select tag.

this line {{ form_widget(form.idkategoria) }} in twig render:

<select id="foo" name="foo">
<option value="">Kategoria</option>
<option value="1">foo</option>
<option value="2">foo</option>

or how to add an 'attr' to placeholder to keep default 'Kategoria' text.

$builder->add('idkategoria', null, array
                ('placeholder' => 'Kategoria',))

1 Answer 1

1

Something like

$builder->add('idkategoria', null, ['attr' => ['placeholder' =>'Kategoria']]) ]

You can find an extract in the official documentation

Sign up to request clarification or add additional context in comments.

1 Comment

by saying or how to add an 'attr' to placeholder I meant adding attribute, f.e. disabled or selected, to placeholder which is option tag. Becouse this line ->add('idkategoria', null, array('placeholder' => 'Kategoria','attr'=> array('required'=>true)) makes required a select tag, not option as I wish (Anyway, I walked the problem in completely different way -css-that is not the answer to my question. You can leave this issue. Thanks)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.