Browse Source

[Form] text is now the default type when not explicitely set and when no data class is set

Fabien Potencier 14 years ago
parent
commit
fd97dd0059
1 changed files with 4 additions and 6 deletions
  1. 4 6
      src/Symfony/Component/Form/FormBuilder.php

+ 4 - 6
src/Symfony/Component/Form/FormBuilder.php

@@ -554,11 +554,13 @@ class FormBuilder
      * @param array                     $options The options
      *
      * @return FormBuilder The builder
-     *
-     * @throws FormException if the data class is not set when creating a property builder
      */
     public function create($name, $type = null, array $options = array())
     {
+        if (null === $type && !$this->dataClass) {
+            $type = 'text';
+        }
+
         if (null !== $type) {
             $builder = $this->getFormFactory()->createNamedBuilder(
                 $type,
@@ -567,10 +569,6 @@ class FormBuilder
                 $options
             );
         } else {
-            if (!$this->dataClass) {
-                throw new FormException(sprintf('The "%s" type cannot be guessed as the data class is not set. Provide the type manually (\'text\', \'password\', ...) or set the data class.', $name));
-            }
-
             $builder = $this->getFormFactory()->createBuilderForProperty(
                 $this->dataClass,
                 $name,