From 085d38557612319919b6b05241aab39b350b1a8b Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Sat, 27 Sep 2014 19:18:59 +0200 Subject: [PATCH 1/4] [Form] Added the 'range' FormType --- CONTRIBUTORS.md | 1 + .../views/Form/form_div_layout.html.twig | 5 +++ .../FrameworkBundle/Resources/config/form.xml | 3 ++ src/Symfony/Component/Form/CHANGELOG.md | 2 +- .../Form/Extension/Core/CoreExtension.php | 1 + .../Form/Extension/Core/Type/RangeType.php | 33 +++++++++++++++++++ 6 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/Form/Extension/Core/Type/RangeType.php diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index a9526431c1983..e38ceab5ecf05 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1105,3 +1105,4 @@ Symfony2 is the result of the work of many people who made the code better - Erik Saunier (snickers) - Matej Žilák (teo_sk) - Vladislav Vlastovskiy (vlastv) + - Joshua Thijssen (jaytaph) 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 699b2f849535e..47c06b8ab1dd8 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 @@ -175,6 +175,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 -%} {% set label = name|humanize %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml index 23d8ec260cafb..b910decba0c9e 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/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 4381726126d48..be50ea2aaef22 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -3,9 +3,9 @@ CHANGELOG 2.6.0 ----- - * added "html5" option to Date, Time and DateTimeFormType to be able to enable/disable HTML5 input date when widget option is "single_text" + * added the html5 "range" FormType 2.5.0 ------ diff --git a/src/Symfony/Component/Form/Extension/Core/CoreExtension.php b/src/Symfony/Component/Form/Extension/Core/CoreExtension.php index a0153a57eb700..940101a905d48 100644 --- a/src/Symfony/Component/Form/Extension/Core/CoreExtension.php +++ b/src/Symfony/Component/Form/Extension/Core/CoreExtension.php @@ -42,6 +42,7 @@ protected function loadTypes() 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 0000000000000..78909e643f5a7 --- /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'; + } +} From c00516b0f7823a97a5b70563eec3d34b6e578cec Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Sat, 27 Sep 2014 20:12:57 +0200 Subject: [PATCH 2/4] Removed manually added line from contributers --- CONTRIBUTORS.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index e38ceab5ecf05..a9526431c1983 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1105,4 +1105,3 @@ Symfony2 is the result of the work of many people who made the code better - Erik Saunier (snickers) - Matej Žilák (teo_sk) - Vladislav Vlastovskiy (vlastv) - - Joshua Thijssen (jaytaph) From 7294c2a652f78b205904683ddfc255e573dd1a1e Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Fri, 3 Oct 2014 21:35:41 +0200 Subject: [PATCH 3/4] Added php template and range tests --- .../views/Form/range_widget.html.php | 1 + src/Symfony/Component/Form/CHANGELOG.md | 1 + .../Form/Tests/AbstractLayoutTest.php | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/range_widget.html.php 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 0000000000000..c711e47f650e5 --- /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 be50ea2aaef22..0f92bd48ffb3d 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -3,6 +3,7 @@ CHANGELOG 2.6.0 ----- + * added "html5" option to Date, Time and DateTimeFormType to be able to enable/disable HTML5 input date when widget option is "single_text" * added the html5 "range" FormType diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index 4755e208e9a51..4ce6a2feca2f0 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -1347,6 +1347,36 @@ public function testLanguage() ); } + 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 testLocale() { $form = $this->factory->createNamed('name', 'locale', 'de_AT'); From ba51c766418adb8f21228bcfc81eb04a078e2e10 Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Fri, 3 Oct 2014 21:40:41 +0200 Subject: [PATCH 4/4] Small CS fixes --- .../FrameworkBundle/Resources/views/Form/range_widget.html.php | 2 +- src/Symfony/Component/Form/Tests/AbstractLayoutTest.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) 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 index c711e47f650e5..4c628f8e005bc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/range_widget.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/range_widget.html.php @@ -1 +1 @@ -block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'range')) ?> +block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'range')); diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index 4ce6a2feca2f0..3fb8f9fd0742a 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -1376,7 +1376,6 @@ public function testRangeWithMinMaxValues() ); } - public function testLocale() { $form = $this->factory->createNamed('name', 'locale', 'de_AT');