diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
index 8ab60af3f4..a5da6c30ad 100644
--- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
+++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
@@ -176,6 +176,11 @@
{{ block('form_widget_simple') }}
{%- endblock email_widget -%}
+{%- block range_widget -%}
+ {% set type = type|default('range') %}
+ {{- block('form_widget_simple') -}}
+{%- endblock range_widget %}
+
{%- block button_widget -%}
{%- if label is empty -%}
{%- if label_format is not empty -%}
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
index 5090309101..a7d09848e4 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
@@ -113,6 +113,9 @@
+
+
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/range_widget.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/range_widget.html.php
new file mode 100644
index 0000000000..4c628f8e00
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/range_widget.html.php
@@ -0,0 +1 @@
+block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'range'));
diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md
index a4c8aa1912..014bdbe26e 100644
--- a/src/Symfony/Component/Form/CHANGELOG.md
+++ b/src/Symfony/Component/Form/CHANGELOG.md
@@ -5,6 +5,7 @@ CHANGELOG
-----
* deprecated option "read_only" in favor of "attr['readonly']"
+ * added the html5 "range" FormType
2.7.0
-----
diff --git a/src/Symfony/Component/Form/Extension/Core/CoreExtension.php b/src/Symfony/Component/Form/Extension/Core/CoreExtension.php
index 231994258e..96e6c1961a 100644
--- a/src/Symfony/Component/Form/Extension/Core/CoreExtension.php
+++ b/src/Symfony/Component/Form/Extension/Core/CoreExtension.php
@@ -63,6 +63,7 @@ class CoreExtension extends AbstractExtension
new Type\PasswordType(),
new Type\PercentType(),
new Type\RadioType(),
+ new Type\RangeType(),
new Type\RepeatedType(),
new Type\SearchType(),
new Type\TextareaType(),
diff --git a/src/Symfony/Component/Form/Extension/Core/Type/RangeType.php b/src/Symfony/Component/Form/Extension/Core/Type/RangeType.php
new file mode 100644
index 0000000000..78909e643f
--- /dev/null
+++ b/src/Symfony/Component/Form/Extension/Core/Type/RangeType.php
@@ -0,0 +1,33 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Form\Extension\Core\Type;
+
+use Symfony\Component\Form\AbstractType;
+
+class RangeType extends AbstractType
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function getParent()
+ {
+ return 'text';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return 'range';
+ }
+}
diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php
index f78be3cb88..ffebc9a68a 100644
--- a/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php
+++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php
@@ -1597,6 +1597,37 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
);
}
+ public function testRange()
+ {
+ $form = $this->factory->createNamed('name', 'range', 42, array('attr' => array('min' => 5)));
+
+ $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
+'/input
+ [@type="range"]
+ [@name="name"]
+ [@value="42"]
+ [@min="5"]
+ [@class="my&class form-control"]
+'
+ );
+ }
+
+ public function testRangeWithMinMaxValues()
+ {
+ $form = $this->factory->createNamed('name', 'range', 42, array('attr' => array('min' => 5, 'max' => 57)));
+
+ $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
+'/input
+ [@type="range"]
+ [@name="name"]
+ [@value="42"]
+ [@min="5"]
+ [@max="57"]
+ [@class="my&class form-control"]
+'
+ );
+ }
+
public function testTextarea()
{
$form = $this->factory->createNamed('name', 'textarea', 'foo&bar', array(
diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
index 60eb034615..d5fc63de8e 100644
--- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
+++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
@@ -1712,6 +1712,35 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
);
}
+ public function testRange()
+ {
+ $form = $this->factory->createNamed('name', 'range', 42, array('attr' => array('min' => 5)));
+
+ $this->assertWidgetMatchesXpath($form->createView(), array(),
+'/input
+ [@type="range"]
+ [@name="name"]
+ [@value="42"]
+ [@min="5"]
+'
+ );
+ }
+
+ public function testRangeWithMinMaxValues()
+ {
+ $form = $this->factory->createNamed('name', 'range', 42, array('attr' => array('min' => 5, 'max' => 57)));
+
+ $this->assertWidgetMatchesXpath($form->createView(), array(),
+'/input
+ [@type="range"]
+ [@name="name"]
+ [@value="42"]
+ [@min="5"]
+ [@max="57"]
+'
+ );
+ }
+
public function testTextarea()
{
$form = $this->factory->createNamed('name', 'textarea', 'foo&bar', array(