Browse Source

[Form] Fixed empty value in choice fields

Bernhard Schussek 14 years ago
parent
commit
3482ff73b7

+ 0 - 1
src/Symfony/Component/Form/Form.php

@@ -459,7 +459,6 @@ class Form implements \IteratorAggregate, FormInterface
             }
         }
 
-
         // Merge form data from children into existing client data
         if (count($this->children) > 0 && $this->dataMapper) {
             $this->dataMapper->mapFormsToData($this->children, $clientData);

+ 4 - 0
src/Symfony/Component/Form/Type/ChoiceType.php

@@ -92,6 +92,9 @@ class ChoiceType extends AbstractType
 
     public function getDefaultOptions(array $options)
     {
+        $multiple = isset($options['multiple']) && $options['multiple'];
+        $expanded = isset($options['expanded']) && $options['expanded'];
+
         return array(
             'multiple' => false,
             'expanded' => false,
@@ -99,6 +102,7 @@ class ChoiceType extends AbstractType
             'choices' => array(),
             'preferred_choices' => array(),
             'csrf_protection' => false,
+            'empty_data' => $multiple || $expanded ? array() : '',
         );
     }