How Can I get autofocus on the first element (buil

2019-06-20 07:52发布

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?

标签: forms symfony
2条回答
在下西门庆
2楼-- · 2019-06-20 08:17
$builder->add('title', 'text', array(
    'attr' => array(
        'autofocus' => true
        )
    );
查看更多
Ridiculous、
3楼-- · 2019-06-20 08:24

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.

查看更多
登录 后发表回答