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
This commit is contained in:
commit
09fabfeb1f
@ -176,6 +176,11 @@
|
|||||||
{{ block('form_widget_simple') }}
|
{{ block('form_widget_simple') }}
|
||||||
{%- endblock email_widget -%}
|
{%- endblock email_widget -%}
|
||||||
|
|
||||||
|
{%- block range_widget -%}
|
||||||
|
{% set type = type|default('range') %}
|
||||||
|
{{- block('form_widget_simple') -}}
|
||||||
|
{%- endblock range_widget %}
|
||||||
|
|
||||||
{%- block button_widget -%}
|
{%- block button_widget -%}
|
||||||
{%- if label is empty -%}
|
{%- if label is empty -%}
|
||||||
{%- if label_format is not empty -%}
|
{%- if label_format is not empty -%}
|
||||||
|
@ -113,6 +113,9 @@
|
|||||||
<service id="form.type.radio" class="Symfony\Component\Form\Extension\Core\Type\RadioType">
|
<service id="form.type.radio" class="Symfony\Component\Form\Extension\Core\Type\RadioType">
|
||||||
<tag name="form.type" alias="radio" />
|
<tag name="form.type" alias="radio" />
|
||||||
</service>
|
</service>
|
||||||
|
<service id="form.type.range" class="Symfony\Component\Form\Extension\Core\Type\RangeType">
|
||||||
|
<tag name="form.type" alias="range" />
|
||||||
|
</service>
|
||||||
<service id="form.type.repeated" class="Symfony\Component\Form\Extension\Core\Type\RepeatedType">
|
<service id="form.type.repeated" class="Symfony\Component\Form\Extension\Core\Type\RepeatedType">
|
||||||
<tag name="form.type" alias="repeated" />
|
<tag name="form.type" alias="repeated" />
|
||||||
</service>
|
</service>
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'range'));
|
@ -5,6 +5,7 @@ CHANGELOG
|
|||||||
-----
|
-----
|
||||||
|
|
||||||
* deprecated option "read_only" in favor of "attr['readonly']"
|
* deprecated option "read_only" in favor of "attr['readonly']"
|
||||||
|
* added the html5 "range" FormType
|
||||||
|
|
||||||
2.7.0
|
2.7.0
|
||||||
-----
|
-----
|
||||||
|
@ -63,6 +63,7 @@ class CoreExtension extends AbstractExtension
|
|||||||
new Type\PasswordType(),
|
new Type\PasswordType(),
|
||||||
new Type\PercentType(),
|
new Type\PercentType(),
|
||||||
new Type\RadioType(),
|
new Type\RadioType(),
|
||||||
|
new Type\RangeType(),
|
||||||
new Type\RepeatedType(),
|
new Type\RepeatedType(),
|
||||||
new Type\SearchType(),
|
new Type\SearchType(),
|
||||||
new Type\TextareaType(),
|
new Type\TextareaType(),
|
||||||
|
33
src/Symfony/Component/Form/Extension/Core/Type/RangeType.php
Normal file
33
src/Symfony/Component/Form/Extension/Core/Type/RangeType.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* 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';
|
||||||
|
}
|
||||||
|
}
|
@ -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()
|
public function testTextarea()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createNamed('name', 'textarea', 'foo&bar', array(
|
$form = $this->factory->createNamed('name', 'textarea', 'foo&bar', array(
|
||||||
|
@ -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()
|
public function testTextarea()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createNamed('name', 'textarea', 'foo&bar', array(
|
$form = $this->factory->createNamed('name', 'textarea', 'foo&bar', array(
|
||||||
|
Reference in New Issue
Block a user