소스 검색

Added html5 email input to the forms

Miha Vrhovnik 14 년 전
부모
커밋
50011fa344

+ 9 - 6
src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml

@@ -25,7 +25,7 @@
         <service id="form.factory" class="%form.factory.class%">
             <argument type="service" id="form.type.loader" />
             <!--
-            All services with tag "form.guesser" are inserted here by 
+            All services with tag "form.guesser" are inserted here by
             AddFormGuessersPass
             -->
             <argument type="collection" />
@@ -36,7 +36,7 @@
             <tag name="form.guesser" />
             <argument type="service" id="validator.mapping.class_metadata_factory" />
         </service>
-        
+
         <!-- CsrfProvider -->
         <service id="form.csrf_provider" class="%form.csrf_provider.class%">
             <argument type="service" id="session" />
@@ -50,17 +50,17 @@
             <argument>%file.temporary_storage.nesting_levels%</argument>
             <argument>%file.temporary_storage.directory%</argument>
         </service>
-        
+
         <!-- ContainerAwareTypeLoader -->
         <service id="form.type.loader" class="%form.type.loader.class%">
             <argument type="service" id="service_container" />
             <!--
-            All services with tag "form.type" are inserted here by 
+            All services with tag "form.type" are inserted here by
             AddFormTypesPass
             -->
             <argument type="collection" />
         </service>
-        
+
         <!-- FieldTypes -->
         <service id="form.type.field" class="Symfony\Component\Form\Type\FieldType">
             <tag name="form.type" alias="field" />
@@ -94,6 +94,9 @@
         <service id="form.type.datetime" class="Symfony\Component\Form\Type\DateTimeType">
             <tag name="form.type" alias="datetime" />
         </service>
+        <service id="form.type.email" class="Symfony\Component\Form\Type\EmailType">
+            <tag name="form.type" alias="email" />
+        </service>
         <service id="form.type.file" class="Symfony\Component\Form\Type\FileType">
             <tag name="form.type" alias="file" />
             <argument type="service" id="file.temporary_storage" />
@@ -143,6 +146,6 @@
         <service id="form.type.url" class="Symfony\Component\Form\Type\UrlType">
             <tag name="form.type" alias="url" />
         </service>
-        
+
     </services>
 </container>

+ 7 - 0
src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/email_widget.html.php

@@ -0,0 +1,7 @@
+<input type="email"
+    <?php echo $view['form']->attributes() ?>
+    name="<?php echo $view->escape($name) ?>"
+    value="<?php echo $view->escape($value) ?>"
+    <?php if ($read_only): ?>disabled="disabled"<?php endif ?>
+    <?php if ($required): ?>required="required"<?php endif ?>
+/>

+ 7 - 0
src/Symfony/Bundle/TwigBundle/Resources/views/Form/div_layout.html.twig

@@ -256,3 +256,10 @@
     </div>
 {% endspaceless %}
 {% endblock form__widget %}
+
+{% block email__widget %}
+{% spaceless %}
+    {% set type = type|default('email') %}
+    {{ block('field__widget') }}
+{% endspaceless %}
+{% endblock email__widget %}

+ 28 - 0
src/Symfony/Component/Form/Type/EmailType.php

@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Form\Type;
+
+use Symfony\Component\Form\FormBuilder;
+use Symfony\Component\Form\FormInterface;
+
+class EmailType extends AbstractType
+{
+    public function getParent(array $options)
+    {
+        return 'field';
+    }
+
+    public function getName()
+    {
+        return 'email';
+    }
+}