title: Symfony2 Sonata admin dynamically change input data based on selected value
body: <p>For one of my objects I need to create some dynamic form rendering... But I cant figure out how to do this in Sonata Admin. For example when I create an object I have a field type. In this field I select a type that my object is going to be. Now when I select the type I want to make a field appear, based on the type. For example, if I select type "Carousel" I want to show a field that is selecting all object form entity Gallery. If I select type "Product" I want to display field with all products to selectt from... How can I acheve that?</p>
  
  <p>Right now I have this:</p>
  
  <pre><code>/**
   * @param FormMapper $formMapper
   */
  protected function configureFormFields(FormMapper $formMapper)
  {
      $formMapper
          -&gt;with('Module', array(
              'class' =&gt; 'col-md-6'
          ))
              -&gt;add('position')
              -&gt;add('type', null, array(
                  'attr' =&gt; array('class' =&gt; 'module_type')
              ))
              -&gt;add('items', 'entity', array(
                  'class' =&gt; 'ApplicationSonataMediaBundle:Gallery'
              ))
          -&gt;end()
      ;
  }
  </code></pre>
  
  <p>And I have overriden the edit template:</p>
  
  <pre><code>{% extends 'SonataAdminBundle:CRUD:edit.html.twig' %}
  
  {% block javascripts %}
      {{ parent() }}
      &lt;script type="text/javascript"&gt;
          $(document).ready(function () {
              $(".module_type").change(function() {
  
              });
  
          });
      &lt;/script&gt;
  
  {% endblock %}
  </code></pre>
  
  <p>As you can see the gallery is hardcoded now..</p>
  
  <p>I cant figure out how to do this now... How to say that if the value selected is this, use that entity in field... The problem is that the way form is rendered in Sonata is very complicated... I dont understand it..</p>
  
  <p>maybe I should use ajax? But again, when I send a value and get the response how to add a field without refresh?</p>
  
  <p>Any help appreciated.</p>