title: Default values for symfony2 choice radio box
body: <p>My project is written using Silex and Symfony Components (i.e. Form component).</p>
  
  <p>I try to create a battery of radio buttons built from a class and I want to preselect one of those radios.</p>
  
  <p>I create form like that:</p>
  
  <pre><code>$form = $app['form.factory']-&gt;createBuilder(new QueryFormType(), $query)
  </code></pre>
  
  <p>where <code>QueryFormType</code> is my custom type (it extends AbstractType) where I define form fields and <code>$query</code> is an entity with default values for the form.</p>
  
  <p>Form fields within <code>QueryFormType</code> look like that (I omitted builder and other fields for clarity):</p>
  
  <pre><code>-&gt;add('contractPeriod', 'filter', array(
    'label' =&gt; 'Contract Period:',
    'choices' =&gt; array(
      '-1' =&gt; 'No period',
      '1' =&gt; '1 month',
      '2' =&gt; '2 months',
      '3' =&gt; '3 months',
      '6' =&gt; '6 months',
      '12' =&gt; '12 months',
      '18' =&gt; '18 months'
    ),
    'expanded' =&gt; TRUE,
    'multiple' =&gt; FALSE
  ))
  </code></pre>
  
  <p><code>$query</code> is an instance of a class that should preselect radio button. In it's constructor you will find:</p>
  
  <pre><code>$this-&gt;contractPeriod = '3';
  </code></pre>
  
  <p>It has correct getters and setters for this property too.</p>
  
  <p>Now. The form and radio buttons are rendered properly. Radio button is preselected to <code>'3' =&gt; '3 months'</code>. When I check radio higher in the definition list (so 2, 1 or -1) form accepts it as a value. But when I check value lower in the defined list (6, 12 or 18) it uses default value set in <code>$query</code>. What the heck?</p>
  
  <p>My question is how to set default value correctly so I can pick whatever other value I want after the form is rendered?</p>
  
  <p>I already tried using 'data' property in the form field definition and it is the same story. I can select only lower values but no higher. I tired to use 'preferred_choices' but it does not work the way I would expect (messed up IDs of the inputs).</p>
  
  <p>I beg you for help.</p>
  
  <p>EDIT</p>
  
  <p>This is how I submit the form:</p>
  
  <pre><code>$form-&gt;submit($request-&gt;query-&gt;get($form-&gt;getName()), FALSE);
  </code></pre>
  
  <p>I found out that if I set clearMissing to TRUE (second argument) it works well but I cannot do partial prefilling (or patch the form). Seem to be a bug.</p>
  
  <p>EDIT</p>
  
  <p>It has something to do with those lines inside Form class of symfony components:</p>
  
  <pre><code>if ($isSubmitted || $clearMissing) {
      $child-&gt;submit($isSubmitted ? $submittedData[$name] : null, $clearMissing);
      unset($submittedData[$name]);
  
      if (null !== $this-&gt;clickedButton) {
          continue;
      }
  
      if ($child instanceof ClickableInterface &amp;&amp; $child-&gt;isClicked()) {
          $this-&gt;clickedButton = $child;
  
          continue;
      }
  
      if (method_exists($child, 'getClickedButton') &amp;&amp; null !== $child-&gt;getClickedButton()) {
          $this-&gt;clickedButton = $child-&gt;getClickedButton();
      }
  }
  </code></pre>
  
  <p>$child->submit updates viewData of its parent (Form in this case) to submited value only if it's lower/equal to default value set in the form. Why?</p>
  
  <p>EDIT</p>
  
  <p>I think that Form component wont submit children after default value that in that case isSubmited == false and clearMissing == false. That makes only values up to default value available. But I don't know.</p>