10000 feature #12067 [Form] Added the 'range' FormType (jaytaph) · symfony/symfony@09fabfe · GitHub
[go: up one dir, main page]

Skip to content

Commit 09fabfe

Browse files
committed
feature #12067 [Form] Added the 'range' FormType (jaytaph)
This PR was submitted for the master branch but it was merged into the 2.8 branch instead (closes #12067). Discussion ---------- [Form] Added the 'range' FormType | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11979 | License | MIT | Doc PR | Implemented the "range" FormType. Commits ------- b52e197 [Form] Added the 'range' FormType
2 parents 15ff865 + b52e197 commit 09fabfe

File tree

8 files changed

+104
-0
lines changed

8 files changed

+104
-0
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@
176176
{{ block('form_widget_simple') }}
177177
{%- endblock email_widget -%}
178178

179+
{%- block range_widget -%}
180+
{% set type = type|default('range') %}
181+
{{- block('form_widget_simple') -}}
182+
{%- endblock range_widget %}
183+
179184
{%- block button_widget -%}
180185
{%- if label is empty -%}
181186
{%- if label_format is not empty -%}

src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@
113113
<service id="form.type.radio" class="Symfony\Component\Form\Extension\Core\Type\RadioType">
114114
<tag name="form.type" alias="radio" />
115115
</service>
116+
<service id="form.type.range" class="Symfony\Component\Form\Extension\Core\Type\RangeType">
117+
<tag name="form.type" alias="range" />
118+
</service>
116119
<service id="form.type.repeated" class="Symfony\Component\Form\Extension\Core\Type\RepeatedType">
117120
<tag name="form.type" alias="repeated" />
118121
</service>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'range'));

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* deprecated option "read_only" in favor of "attr['readonly']"
8+
* added the html5 "range" FormType
89

910
2.7.0
1011
-----

src/Symfony/Component/Form/Extension/Core/CoreExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ protected function loadTypes()
6363
new Type\PasswordType(),
6464
new Type\PercentType(),
6565
new Type\RadioType(),
66+
new Type\RangeType(),
6667
new Type\RepeatedType(),
6768
new Type\SearchType(),
6869
new Type\TextareaType(),
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Extension\Core\Type;
13+
14+
use Symfony\Component\Form\AbstractType;
15+
16+
class RangeType extends AbstractType
17+
{
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
public function getParent()
22+
{
23+
return 'text';
24+
}
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function getName()
30+
{
31+
return 'range';
32+
}
33+
}

src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,37 @@ public function testRadioWithValue()
15971597
);
15981598
}
15991599

1600+
public function testRange()
1601+
{
1602+
$form = $this->factory->createNamed('name', 'range', 42, array('attr' => array('min' => 5)));
1603+
1604+
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
1605+
'/input
1606+
[@type="range"]
1607+
[@name="name"]
1608+
[@value="42"]
1609+
[@min="5"]
1610+
[@class="my&class form-control"]
1611+
'
1612+
);
1613+
}
1614+
1615+
public function testRangeWithMinMaxValues()
1616+
{
1617+
$form = $this->factory->createNamed('name', 'range', 42, array('attr' => array('min' => 5, 'max' => 57)));
1618+
1619+
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
1620+
'/input
1621+
[@type="range"]
1622+
[@name="name"]
1623+
[@value="42"]
1624+
[@min="5"]
1625+
[@max="57"]
1626+
[@class="my&class form-control"]
1627+
'
1628+
);
1629+
}
1630+
16001631
public function testTextarea()
16011632
{
16021633
$form = $this->factory->createNamed('name', 'textarea', 'foo&bar', array(

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,35 @@ public function testRadioWithValue()
17121712
);
17131713
}
17141714

1715+
public function testRange()
1716+
{
1717+
$form = $this->factory->createNamed('name', 'range', 42, array('attr' => array('min' => 5)));
1718+
1719+
$this->assertWidgetMatchesXpath($form->createView(), array(),
1720+
'/input
1721+
[@type="range"]
1722+
[@name="name"]
1723+
[@value="42"]
1724+
[@min="5"]
1725+
'
1726+
);
1727+
}
1728+
1729+
public function testRangeWithMinMaxValues()
1730+
{
1731+
$form = $this->factory->createNamed('name', 'range', 42, array('attr' => array('min' => 5, 'max' => 57)));
1732+
1733+
$this->assertWidgetMatchesXpath($form->createView(), array(),
1734+
'/input
1735+
[@type="range"]
1736+
[@name="name"]
1737+
[@value="42"]
1738+
[@min="5"]
1739+
[@max="57"]
1740+
'
1741+
);
1742+
}
1743+
17151744
public function testTextarea()
17161745
{
17171746
$form = $this->factory->createNamed('name', 'textarea', 'foo&bar', array(

0 commit comments

Comments
 (0)
0