Skip to content

Commit

Permalink
feature #22679 [Form] Add tel and color types (apetitpa)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 3.4 branch (closes #22679).

Discussion
----------

[Form] Add tel and color types

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22596
| License       | MIT
| Doc PR        | not provided yet

Commits
-------

5b07ca7 [Form] Add tel and color types
  • Loading branch information
nicolas-grekas committed Oct 2, 2017
2 parents f86b4c4 + 5b07ca7 commit 579e3b3
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 8 deletions.
Expand Up @@ -239,6 +239,16 @@
{{ block('button_widget') }}
{%- endblock reset_widget -%}

{%- block tel_widget -%}
{%- set type = type|default('tel') -%}
{{ block('form_widget_simple') }}
{%- endblock tel_widget -%}

{%- block color_widget -%}
{%- set type = type|default('color') -%}
{{ block('form_widget_simple') }}
{%- endblock color_widget -%}

{# Labels #}

{%- block form_label -%}
Expand Down
@@ -0,0 +1 @@
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'color'));
@@ -0,0 +1 @@
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'tel'));
2 changes: 2 additions & 0 deletions src/Symfony/Component/Form/Extension/Core/CoreExtension.php
Expand Up @@ -77,6 +77,8 @@ protected function loadTypes()
new Type\SubmitType(),
new Type\ResetType(),
new Type\CurrencyType(),
new Type\TelType(),
new Type\ColorType(),
);
}
}
33 changes: 33 additions & 0 deletions src/Symfony/Component/Form/Extension/Core/Type/ColorType.php
@@ -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 ColorType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function getParent()
{
return TextType::class;
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'color';
}
}
33 changes: 33 additions & 0 deletions src/Symfony/Component/Form/Extension/Core/Type/TelType.php
@@ -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 TelType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function getParent()
{
return TextType::class;
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'tel';
}
}
30 changes: 30 additions & 0 deletions src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php
Expand Up @@ -2468,4 +2468,34 @@ public function testButtonAttributeNameRepeatedIfTrue()
// foo="foo"
$this->assertSame('<button type="button" id="button" name="button" foo="foo" class="btn-default btn">[trans]Button[/trans]</button>', $html);
}

public function testTel()
{
$tel = '0102030405';
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TelType', $tel);

$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
'/input
[@type="tel"]
[@name="name"]
[@class="my&class form-control"]
[@value="0102030405"]
'
);
}

public function testColor()
{
$color = '#0000ff';
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ColorType', $color);

$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
'/input
[@type="color"]
[@name="name"]
[@class="my&class form-control"]
[@value="#0000ff"]
'
);
}
}
28 changes: 28 additions & 0 deletions src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Expand Up @@ -2463,4 +2463,32 @@ public function testAttributesNotTranslatedWhenTranslationDomainIsFalse()
$this->assertMatchesXpath($html, '/form//input[@title="Foo"]');
$this->assertMatchesXpath($html, '/form//input[@placeholder="Bar"]');
}

public function testTel()
{
$tel = '0102030405';
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TelType', $tel);

$this->assertWidgetMatchesXpath($form->createView(), array(),
'/input
[@type="tel"]
[@name="name"]
[@value="0102030405"]
'
);
}

public function testColor()
{
$color = '#0000ff';
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ColorType', $color);

$this->assertWidgetMatchesXpath($form->createView(), array(),
'/input
[@type="color"]
[@name="name"]
[@value="#0000ff"]
'
);
}
}
Expand Up @@ -5,6 +5,7 @@
"Symfony\\Component\\Form\\Extension\\Core\\Type\\CheckboxType",
"Symfony\\Component\\Form\\Extension\\Core\\Type\\ChoiceType",
"Symfony\\Component\\Form\\Extension\\Core\\Type\\CollectionType",
"Symfony\\Component\\Form\\Extension\\Core\\Type\\ColorType",
"Symfony\\Component\\Form\\Extension\\Core\\Type\\CountryType",
"Symfony\\Component\\Form\\Extension\\Core\\Type\\CurrencyType",
"Symfony\\Component\\Form\\Extension\\Core\\Type\\DateIntervalType",
Expand All @@ -27,6 +28,7 @@
"Symfony\\Component\\Form\\Extension\\Core\\Type\\ResetType",
"Symfony\\Component\\Form\\Extension\\Core\\Type\\SearchType",
"Symfony\\Component\\Form\\Extension\\Core\\Type\\SubmitType",
"Symfony\\Component\\Form\\Extension\\Core\\Type\\TelType",
"Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType",
"Symfony\\Component\\Form\\Extension\\Core\\Type\\TextareaType",
"Symfony\\Component\\Form\\Extension\\Core\\Type\\TimeType",
Expand Down
Expand Up @@ -3,12 +3,12 @@
----------------------------------------------------------------

BirthdayType, ButtonType, CheckboxType, ChoiceType, CollectionType
CountryType, CurrencyType, DateIntervalType, DateTimeType, DateType
EmailType, FileType, FormType, HiddenType, IntegerType
LanguageType, LocaleType, MoneyType, NumberType, PasswordType
PercentType, RadioType, RangeType, RepeatedType, ResetType
SearchType, SubmitType, TextType, TextareaType, TimeType
TimezoneType, UrlType
ColorType, CountryType, CurrencyType, DateIntervalType, DateTimeType
DateType, EmailType, FileType, FormType, HiddenType
IntegerType, LanguageType, LocaleType, MoneyType, NumberType
PasswordType, PercentType, RadioType, RangeType, RepeatedType
ResetType, SearchType, SubmitType, TelType, TextType
TextareaType, TimeType, TimezoneType, UrlType

Service form types
------------------
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/composer.json
Expand Up @@ -39,9 +39,9 @@
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
"symfony/dependency-injection": "<3.3",
"symfony/doctrine-bridge": "<2.7",
"symfony/framework-bundle": "<2.7",
"symfony/framework-bundle": "<3.4",
"symfony/http-kernel": "<3.3.5",
"symfony/twig-bridge": "<2.7"
"symfony/twig-bridge": "<3.4"
},
"suggest": {
"symfony/validator": "For form validation.",
Expand Down

0 comments on commit 579e3b3

Please sign in to comment.