Skip to content

Commit ae9fbbe

Browse files
jaytaphwebmozart
authored andcommitted
[Form] Added the 'range' FormType
1 parent 8f76ccf commit ae9fbbe

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

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
-----

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(),

Extension/Core/Type/RangeType.php

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 <[email protected]>
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+
}

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(

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)