title: Symfony2 Collection of Choises
body: <p>I'm making my first Symfony web app.
  Now after creating a couple of forms I found some problem creating a form with a collection of choises.</p>
  
  <p>Creating a collection of TextTypes is very easy and is working in a couple of my forms. Now when I create a collections of ChoiseTypes it does not show anything on the screen. After checking the html code it only show the select statement without any options. Also the prototype contains only the select and not the options.</p>
  
  <p>Where is how I add the collections of choises to the form:</p>
  
  <pre><code>-&gt;add('fieldTypes', CollectionType::class, array(
                      'entry_type' =&gt; ChoiceType::class,
                      'entry_options' =&gt; array(
                          'choices' =&gt; $fieldTypes,
                          'required' =&gt; true,
                     ),
                       'allow_add' =&gt; true,
                      'allow_delete' =&gt; true,
                      'prototype' =&gt; true,
                  ))
  </code></pre>
  
  <p>And this is the twig part of the sollution:</p>
  
  <pre><code>&lt;td&gt;
                          &lt;ul id="typeTable" data-prototype="{{ form_widget(form.fieldTypes.vars.prototype)|e }}"&gt;
                              {% for fieldType in form.fieldTypes %}
                                  &lt;li&gt;
                                      {{ form_widget(fieldType) }}
                                  &lt;/li&gt;
                              {% endfor %}
                          &lt;/ul&gt;
                      &lt;/td&gt;
  </code></pre>
  
  <p>And the full JS code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          // keep track of how many email fields have been rendered
          var nameCount = '{{ form.fieldNames|length }}';
          var typeCount = '{{ form.fieldTypes|length }}';
          var optionCount = '{{ form.fieldOptions|length }}';
  
          jQuery(document).ready(function () {
              jQuery('#add-new-field').click(function (e) {
                  e.preventDefault();
  
                  var nameList = jQuery('#nameTable');
                  var typeList = jQuery('#typeTable');
                  var optionList = jQuery('#optionTable');
  
                  // grab the prototype template
                  var newNameWidget = nameList.attr('data-prototype');
                  var newTypeWidget = typeList.attr('data-prototype');
                  var newOptionWidget = optionList.attr('data-prototype');
  
                  //var newTypeWidget = jQuery('#fieldType_prototype');
                  // replace the "__name__" used in the id and name of the prototype
                  // with a number that's unique to your emails
                  // end name attribute looks like name="contact[emails][2]"
                  newNameWidget = newNameWidget.replace(/__name__/g, nameCount);
                  newTypeWidget = newTypeWidget.replace(/__name__/g, typeCount);
                  newOptionWidget = newOptionWidget.replace(/__name__/g, optionCount);
  
                  var $options = $("#fieldType_prototype &gt; option").clone();
  
                  //$(newTypeWidget).append($options);
  
                  $("#form_fieldTypes_" + typeCount).html( $("#fieldType_prototype").html() );
  
                 // newTypeWidget.attr("id","form_fieldTypes_" + typeCount);
                 // newTypeWidget.attr('name', 'form[fieldTypes][' + typeCount + ']');
                  nameCount++;
                  typeCount++;
                  optionCount++;
  
                  // create a new list element and add it to the list
                  var newLi = jQuery('&lt;li&gt;&lt;/li&gt;').html(newNameWidget);
                  newLi.appendTo(nameList);
  
                  var newLi = jQuery('&lt;li&gt;&lt;/li&gt;').html(newTypeWidget);
                  newLi.appendTo(typeList);
  
                  var newLi = jQuery('&lt;li&gt;&lt;/li&gt;').html(newOptionWidget);
                  newLi.appendTo(optionList);
              });
          })
      &lt;/script&gt;
  </code></pre>
  
  <p>Variable $fieldTypes contains this:</p>
  
  <pre><code>array('Text Field' =&gt; TextType::class,
            'Text area' =&gt; TextareaType::class,
            'Email' =&gt; EmailType::class,
            'Number' =&gt; IntegerType::class,
            'Url' =&gt; UrlType::class,
            'Drop down' =&gt; ChoiceType::class,
            'Date' =&gt; DateType::class,
            'Checkbox' =&gt; CheckboxType::class);      
    }
  </code></pre>
  
  <p>Can someone help me with this issue?</p>