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

问题描述 投票:0回答:5

我在

Controller
中制作表格,如下所示。

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

然后在twig文件中...

{{form_widget(form.commentToMutor)}}

显示文本输入框,但太小了。

如何更改

TextBox

的大小
symfony
5个回答
22
投票

扩展@manseuk的答案(我没有足够的声誉来发表评论),如果您愿意,您还可以在表单生成器中指定html样式属性:

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

已编辑,从

html attribute for width
更改为
html style attribute


7
投票

您可以在表单字段中添加

class
:

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

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

.myclass {
   width: 200px;
}

此处

attr
属性的文档


3
投票

或者在树枝文件中:

{# Define CSS class and call #}
{{ form_widget(form.commentToMutor, { 'attr': {'class': 'myclass'} }) }}

{# ... or enter width directly #}
{{ form_widget(form.commentToMutor, { 'attr': {'style': 'width: 200px'} }) }}

更多这里


2
投票

直接设置宽度对我来说不起作用。我必须通过样式来设置它。当然,这是一个简单的修复方法,正确的方法是像其他人建议的那样使用 css 类。

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

0
投票

使用类来选择输入。

CSS

.w-input-1 input{width: 4em;}
.w-input-2 input{width: 8em;}
.w-input-3 ...

在 twig、html 中...

    <div class="w-input-1">
        {{ form_row(form.smallinputtext) }}
    </div>...

or 
   {{ form_widget(form.commentToMutor, { 'attr': {'class': 'smallinputtext'} }) }}

在表单类型中...

$form->add('smalltext', null, [
           'attr' => array('class' => 'w-input-1')
          )
   );
© www.soinside.com 2019 - 2024. All rights reserved.