Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] Added the 'range' FormType #12067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@
<service id="form.type.radio" class="Symfony\Component\Form\Extension\Core\Type\RadioType">
<tag name="form.type" alias="radio" />
</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">
<tag name="form.type" alias="repeated" />
</service>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'range'));
1 change: 1 addition & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line should not be removed

* 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
------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
33 changes: 33 additions & 0 deletions src/Symfony/Component/Form/Extension/Core/Type/RangeType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* 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';
}
}
29 changes: 29 additions & 0 deletions src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,35 @@ 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');
Expand Down