1

How can I add a attribute to field only using FormBuilder (not twig form theming). When I use

$builder->add('body',null,array('attr' => array('class' => 'tinymce')));

It's add a tinymce class to label too. Please help.

Mikhail
  • 2,542
  • 4
  • 29
  • 40
  • It's not possible to do this without any changes to the form theme. I asked something very similar before. Take a look at the accepted answer: http://stackoverflow.com/q/11034736/1456376 – insertusernamehere Aug 17 '12 at 19:34
  • ok, thanks. I think I will use a JS for that: `$('label.tinymce').removeClass('tinymce');` because it is shortest – Mikhail Aug 18 '12 at 05:08
  • I just retested with my installation of Symfony2 - and this code applies `class` only to `input`, label is not changed. Which version of Symfony2 do you use? – Vitalii Zurian Aug 18 '12 at 21:51

1 Answers1

0
$builder
            ->add('email', EmailType::class ) //will display default label
            ->add('username', TextType::class,
                array(
                    'label' => false,
                    'attr' => array(
//                      'class' => 'myclassfrom.css', //<- this one is realy avesome
                        'placeholder' => 'UsernameExample',
                        'autofocus' => '',

                    ),
            ))
zoore
  • 293
  • 5
  • 13