【问题标题】:How can I add css classes to ChoseType?如何将 css 类添加到 ChoseType?
【发布时间】:2017-09-27 18:03:33
【问题描述】:

我正在尝试将一些 css 类添加到 ChoiceType 表单中,在我的情况下是一个单选框(我将选项“multiple”设置为 false,将选项“expanded”设置为 true)。

我不知道应该使用哪个选项,我尝试了 attr 和choice_attr,但没有成功。

我的问题是:

如何给收音机和收音机的文字添加css类?

  $builder
    ->add('enLigne', ChoiceType::class, [
                    'choices' => $publier,
                    'attr' => [
                        'class' => 'radio',
                    ],
'choice_attr' => function($val, $key, $index) {
                    return ['class' => 'ace input-lg'];
                },
                    'multiple' => false,
                    'expanded' => true,
                    'label' => 'Publier *',
                    'label_attr' => [
                        "class" => "smaller lighter blue",
                        "style" => "font-size: 21px;",
                    ]
                ])

我想做一个这样的单选框:

HTML 代码:

<div class="radio">
     <label>
     <input name="form-field-radio" type="radio" class="ace input-lg">
     <span class="lbl bigger-120"> large radio</span>
     </label></div>

【问题讨论】:

  • 使用add第三个参数写这个array('attr'=&gt;array('class', 'attr_name'))
  • 对不起,如何使用添加第三个参数?
  • 对不起,看错了你的代码...你已经使用了我上面说的...如果您需要在表单中自定义另一个特定元素,那么直接使用css...your_class input[type=radio]
  • 对不起,我不太明白你能不能把代码。
  • 您好,我需要帮助。

标签: css symfony symfony-forms


【解决方案1】:

不要使用 php 添加 html 属性。而是在呈现表单时添加这些属性。示例:

{{ form_start(form) }}
    {{ form_row(form.enLigne, { 'attr': { 'class': 'smaller lighter blue' } } }}
{{ form_end(form)

【讨论】:

  • 我已按照文档进行操作,但没有找到解决方案
猜你喜欢
  • 2017-06-26
  • 2015-02-10
  • 1970-01-01
  • 2023-03-09
  • 2021-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多