我在哪里可以更改表单文本框的大小?

whi*_*ear 5 symfony

我在Controller下面写这个表格.

$form = $this->createFormBuilder($row)
->add('comment',null,array('label' => 'input comment'))
Run Code Online (Sandbox Code Playgroud)

然后在树枝文件中......

{{form_widget(form.commentToMutor)}}
Run Code Online (Sandbox Code Playgroud)

它显示文本输入框,但它太小.

如何改变大小 TextBox

Dan*_*cas 17

扩展@manseuk的答案(没有足够的声誉发表评论),你也可以在表单构建器中指定html样式属性,如果你喜欢:

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

编辑html attribute for widthhtml style attribute.

  • 肯定`width`应该是`style`属性的一部分,所以''attr'=> array('style'=>'width:200px'`肯定应该有效.但是你原来的回答是:''attr'=> array('width'=>'200')`它只会产生html代码`<input type ="text"width ="128">`其中`width`属性被忽略,因为它没有意义.我认为接受答案的人可能已经调整了你的代码("样式"或"大小"),但只是简单地接受了答案.所以我想知道是否认为编辑答案是否值得? (4认同)

Man*_*eUK 6

您可以class在表单字段中添加:

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

然后创建与该类相关的CSS:

.myclass {
   width: 200px;
}
Run Code Online (Sandbox Code Playgroud)

attr这里属性的文档