title: How to add an Event Listener to a dynamically added field using Symfony Forms
body: <p>I am using event listeners to dynamically modify a form. I want to add another event listener to a field that was added dynamically. Im not sure how to accomplish this.</p>
  
  <pre><code>public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder-&gt;add('first_field','choice',array(
          'choices'=&gt;array('1'=&gt;'First Choice','2'=&gt;'Second Choice')
      ));
  
      $builder-&gt;addEventListener(FormEvents::PRE_SET_DATA, array($this, 'preSetData'));
      $builder-&gt;get('first_field')-&gt;addEventListener(FormEvents::POST_SUBMIT, array($this, 'postSubmit'));
  }
  
  public function preSetData(FormEvent $event)
  {
      $form = $event-&gt;getForm();
      $form-&gt;add('second_field','choice',array(
          'choices'=&gt;array('1'=&gt;'First Choice','2'=&gt;'Second Choice')
      ));
      //Some how add an event listener to this field
  
  }
  
  public function postSubmit(FormEvent $event)
  {
      $form = $event-&gt;getForm()-&gt;getParent();
      $form-&gt;add('second_field','choice',array(
          'choices'=&gt;array('1'=&gt;'First Choice','2'=&gt;'Second Choice')
      ));
      //Some how add an event listener to this field
  }
  </code></pre>
  
  <p>I have trie just using the <code>$builder</code> in the <code>buildForm</code> function to add the event listener to the <code>second_field</code> but because the field doesnt exist when the form is initially generated it throws an error.</p>
  
  <p>If i try and add the new event listener inside the first event listener by doing:</p>
  
  <pre><code>$form-&gt;get('second_field')-&gt;addEventListener(...)
  </code></pre>
  
  <p>Then i get the error: </p>
  
  <pre><code>Call to undefined method Symfony\Component\Form\Form::addEventListener() 
  </code></pre>
  
  <p>Any suggestions would be welcome.</p>