Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

forms

symfony

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 on my first field "title", when i display the form?

like image 646
Bissap Avatar asked Aug 30 '15 17:08

Bissap


2 Answers

$builder->add('title', 'text', array(
    'attr' => array(
        'autofocus' => true
        )
    );
like image 113
malcolm Avatar answered Nov 15 '22 22:11

malcolm


The realy crossbrowser way is to type

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

This code produces just autofocus attribute without = sign and any value.

like image 38
Dmitriy Korobkov Avatar answered Nov 15 '22 22:11

Dmitriy Korobkov