浏览代码

[Form] Use HTML5 number and url input types for number and url fields

Jordi Boggiano 14 年之前
父节点
当前提交
ae40a5da53

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/number_field.php.html

@@ -1,4 +1,4 @@
-<input type="text"
+<input type="number"
     id="<?php echo $field->getId() ?>"
     name="<?php echo $field->getName() ?>"
     value="<?php echo $field->getDisplayedData() ?>"

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

@@ -0,0 +1,7 @@
+<input type="url"
+    id="<?php echo $field->getId() ?>"
+    name="<?php echo $field->getName() ?>"
+    value="<?php echo $field->getDisplayedData() ?>"
+    <?php if ($field->isDisabled()): ?>disabled="disabled"<?php endif ?>
+    <?php echo $view['form']->attributes($attr) ?>
+/>

+ 20 - 7
src/Symfony/Bundle/TwigBundle/Resources/views/form.twig.html

@@ -62,8 +62,12 @@
 
 {% block text_field %}
 {% spaceless %}
-    {#{% set attr.maxlength = attr.maxlength|default(field.maxlength) %}#}
-    <input type="text" {{ block('field_attributes') }} value="{{ field.displayedData }}" />
+    {% if attr.type is defined and attr.type != "text" %}
+        <input {{ block('field_attributes') }} value="{{ field.displayedData }}" />
+    {% else %}
+        {#{% set attr.maxlength = attr.maxlength|default(field.maxlength) %}#}
+        <input type="text" {{ block('field_attributes') }} value="{{ field.displayedData }}" />
+    {% endif %}
 {% endspaceless %}
 {% endblock text_field %}
 
@@ -144,7 +148,7 @@
 
 {% block date_field %}
 {% spaceless %}
-    {% if field.isfield %}
+    {% if field.isField %}
         {{ block('text_field') }}
     {% else %}
         {{ field.pattern|replace({ '{{ year }}': form_field(field.year), '{{ month }}': form_field(field.month), '{{ day }}': form_field(field.day) })|raw }}
@@ -155,24 +159,33 @@
 {% block time_field %}
 {% spaceless %}
     {# TODO the next line should be set attr.size = 1, but that's not supported yet by Twig #}
-    {% if field.isfield %}{% set attr = { 'size': 1 } %}{% endif %}
+    {% if field.isField %}{% set attr = { 'size': 1 } %}{% endif %}
     {{ form_field(field.hour, attr) }}:{{ form_field(field.minute, attr) }}{% if field.isWithSeconds %}:{{ form_field(field.second, attr) }}{% endif %}
 {% endspaceless %}
 {% endblock time_field %}
 
 {% block number_field %}
 {% spaceless %}
-    <input type="text" {{ block('field_attributes') }} value="{{ field.displayedData }}" />
+    {# TODO the next line should be set attr.type = 'number', but that's not supported yet by Twig #}
+    {% set attr = { 'type': 'number' } %}
+    {{ block('text_field') }}
 {% endspaceless %}
 {% endblock number_field %}
 
 {% block money_field %}
 {% spaceless %}
-    {% set widget %}{{ block('number_field') }}{% endset %}
-    {{ field.pattern|replace({ '{{ widget }}': widget })|raw }}
+    {{ field.pattern|replace({ '{{ widget }}': block('number_field') })|raw }}
 {% endspaceless %}
 {% endblock money_field %}
 
+{% block url_field %}
+{% spaceless %}
+    {# TODO the next line should be set attr.type = 'url', but that's not supported yet by Twig #}
+    {% set attr = { 'type': 'url' } %}
+    {{ block('text_field') }}
+{% endspaceless %}
+{% endblock url_field %}
+
 {% block percent_field %}
 {% spaceless %}
     {{ block('text_field') }} %