Where can I resize the text field of a form?

I am making a form in Controller as shown below.

 $form = $this->createFormBuilder($row) ->add('comment',null,array('label' => 'input comment')) 

then in the twig file ...

 {{form_widget(form.commentToMutor)}} 

An input text box is displayed here, but it is too small.

How to resize a TextBox

+4
source share
4 answers

@Manseuk answer extension (doesn't have enough reputation to post a comment), you can also specify the html style attribute inside the form builder, if you prefer:

 $form = $this->createFormBuilder($row) ->add('comment', null, array( 'label' => 'input comment', 'attr' => array('style' => 'width: 200px') ) ); 

Edited from html attribute for width to html style attribute .

+15
source

You can add class to the form field:

 $form = $this->createFormBuilder($row) ->add('comment',null,array( 'label' => 'input comment', 'attr' => array('class' => 'myclass') ) ); 

and then create CSS related to this class:

 .myclass { width: 200px; } 

The docs for the attr attribute are here

+4
source

Or in the twig file:

 {# Define CSS class and call #} {{ form_widget(form.commentToMutor, { 'attr': {'class': 'myclass'} }) }} {# ... or enter width directly #} {{ form_widget(form.commentToMutor, { 'attr': {'style': 'width: 200px'} }) }} 

More here

+3
source

Setting the width did not work directly for me. I had to set it in style. Of course, this is easy to fix, the correct way is to use the css class, as others have suggested.

 $form = $this->createFormBuilder($row) ->add('comment', null, array( 'label' => 'input comment', 'attr' => array('style' => 'width:200px') ) ); 
+1
source

Source: https://habr.com/ru/post/1484168/


All Articles