How can I get autofocus on the first symfony element (buildform)

In my TopicType class, I used:

public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('title', 'text') ->add('content', 'ckeditor', array( 'label' => 'Contenu', 'config_name' => 'my_custom_config', 'config' => array('language' => 'fr'),)) ->add('save', 'submit') ; } 

How can I get autofocus in my first "title" field when I show the form?

+5
source share
2 answers
 $builder->add('title', 'text', array( 'attr' => array( 'autofocus' => true ) ); 
+7
source

The real way for a crossbrowser is to enter

 $builder->add('title', 'text', array( 'attr' => array( 'autofocus' => null ) ); 

This code only generates an unsigned autofocus attribute and any value.

+1
source

All Articles