title: Symfony and Bootstrap dateTimePicker : expected a string
body: <p>I am trying to create a DateTimePickerType to easily add a Bootstrap dateTimePicker to a field, simply by using the type "date_time_picker" in the Form Builder.<br>
  Unfortunately I am running into some problems. Specifically, Symfony is giving me this error :</p>
  
  <blockquote>
    <p>Symfony\Component\Validator\ConstraintViolation<br>
    Object(Symfony\Component\Form\Form).children[startDate] = Object(DateTime) - 2016-10-16T10:45:00+0200<br>
    Caused by:<br>
    Symfony\Component\Form\Exception\TransformationFailedException<br>
    Unable to reverse value for property path "startDate": Expected a string.
    Caused by:<br>
    Symfony\Component\Form\Exception\TransformationFailedException<br>
    Expected a string.</p>
  </blockquote>
  
  <p>So apparently my form is sending a DateTime object to my Controller, who has trouble converting it to String. In the database, the field is of type datetime. </p>
  
  <p>Here is my DateTimePickerType :</p>
  
  <pre><code>class DateTimePickerType extends AbstractType
  {
      /**
       * @return string
       */
      public function getParent()
      {
          return 'datetime';
      }
  
      /**
       * @param OptionsResolverInterface $resolver
       */
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
  
          $resolver-&gt;setDefaults(
              array(
                  'empty_data' =&gt; new \DateTime(),
                  'widget' =&gt; "single_text",
                  'attr' =&gt; array(
                      'class' =&gt; 'addInput col-xs-12 dateSize noPadding noOutline dateTimePicker',
                  ),
                  'format' =&gt; 'YYYY-MM-DD HH:mm',
                  'date_format'=&gt;"dd/MM/yyyy hh:mm",
                  'html5'    =&gt; false,
              )
          );
      }
  
      /**
       * @param FormView $view
       * @param FormInterface $form
       * @param array $options
       */
      public function buildView(FormView $view, FormInterface $form, array $options)
      {
          $view-&gt;vars = array_replace($view-&gt;vars, array(
              'empty_data' =&gt; $options['empty_data'],
              'widget' =&gt; $options['widget'],
              'format' =&gt; $options['date_format'],
          ));
      }
  
      /**
       * @return string
       */
      public function getName()
      {
          return 'date_time_picker';
      }
  }
  </code></pre>
  
  <p>I have tried many different options for the resolver. If I remove the "new \DateTime()" in "empty_data", my form now sends a <code>null</code> value, and I get a nice SQL error trying to insert null into the database.</p>
  
  <p>Snippet of <em>form_template.html.twig</em> :</p>
  
  <pre><code>{% block date_time_picker_widget %}
      &lt;div class='input-group date' id='date-time-picker-{{ id }}'&gt;
          &lt;input type="text" class="form-control" /&gt;
          &lt;span class="input-group-addon"&gt;&lt;i class="fa fa-clock-o"&gt;&lt;/i&gt;&lt;/span&gt;
      &lt;/div&gt;
      {% include 'VMSFormTypeBundle:Template:date_time_picker_script.html.twig' %} {# link to the direct js script to make it datetimepicker #}
  {% endblock %}
  </code></pre>
  
  <p>In <em>date_time_picker_script.html.twig</em> :</p>
  
  <pre><code>{% autoescape false %}
      &lt;script type="text/javascript"&gt;
          $(function () {
              $('#date-time-picker-{{ id }}').datetimepicker();
          });
      &lt;/script&gt;
  {% endautoescape %}
  </code></pre>
  
  <p>Snippet of my <em>Form Builder</em> :</p>
  
  <pre><code>$builder
  -&gt;add('startDate','date_time_picker')
  </code></pre>
  
  <p>Thanks in advance</p>
  
  <p><strong>EDIT</strong> : Just noticed the datetime that is sent by the form ignores what I select, and instead sends the current datetime (current day, hour and minute). </p>