2015-08-30 8 views
5

In meinem Topictype Klasse, habe ich:Wie kann ich Autofokus auf das erste Element (buildform) symfony

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') 
    ; 
} 

Wie kann ich Autofokus auf meinem ersten Feld „Titel“ zu bekommen, wenn ich das Formular angezeigt werden?

Antwort

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

Hallo @ Malcolm, es ist Arbeit mit Google Chrome, aber nicht auf Firefox. '' – Bissap

+0

Sie können ''autofocus' => 'autofocus'' setzen – malcolm

+0

Jetzt, Ich habe '' aber es funktioniert immer noch nicht ... – Bissap

1

Die wirklich cross Weg ist

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

Dieser Code nur autofocus ohne = Zeichen erzeugt und einen beliebigen Wert Attribut eingeben.

Verwandte Themen