Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 Form Customization

I want something like this:

<textarea rows="30" cols="70"  class="TextBox" style="height:100px;">

but inside my symfony2 aplication and not in the twig template i tried this:

        $builder->add('history', 'textarea', array('label' => 'Nome' , 'max_length' => 1048576 , 'rows' = 30 , 'cols' = 70));

but i get "rows" and "cols" are not options...

in the twig i want something like this:

<label for="history">{{'form_anamnese_history'}}</label>
{{ form_widget(form.history) }}

to be a forum-post-like textbox!

like image 939
Munir Avatar asked Oct 18 '12 16:10

Munir


People also ask

What is Form_widget?

form_widget(form_view, variables) is a Twig function to render the HTML widget of a given field. If you apply this to an entire form or collection of fields, each underlying form row will be rendered.

What is form rendering?

This form is used to export the currently displayed graphics scene to an image file or to a geometric scene description file suitable for use by one of several external renderers, which can produce a final image.


2 Answers

Use the attr array, as explained in the documentation:

$builder->add('history', 'textarea', array(     'attr' => array('cols' => '5', 'rows' => '5'), )); 
like image 185
Juan Sosa Avatar answered Oct 18 '22 16:10

Juan Sosa


You can set the display attributes for textarea in Twig rather than in the form:

{{ form_widget(edit_form.comment, { 'attr': { 
  'style' : 'width:525px', 
  'rows' : '4', 
  'cols' : '30' }} ) }}

As mentioned above, it is better practice to set this in CSS if possible however.

like image 29
Richard F Avatar answered Oct 18 '22 16:10

Richard F