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

Skip to content

Commit 579e3b3

Browse files
feature #22679 [Form] Add tel and color types (apetitpa)
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
2 parents f86b4c4 + 5b07ca7 commit 579e3b3

File tree

11 files changed

+148
-8
lines changed

11 files changed

+148
-8
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@
239239
{{ block('button_widget') }}
240240
{%- endblock reset_widget -%}
241241

242+
{%- block tel_widget -%}
243+
{%- set type = type|default('tel') -%}
244+
{{ block('form_widget_simple') }}
245+
{%- endblock tel_widget -%}
246+
247+
{%- block color_widget -%}
248+
{%- set type = type|default('color') -%}
249+
{{ block('form_widget_simple') }}
250+
{%- endblock color_widget -%}
251+
242252
{# Labels #}
243253

244254
{%- block form_label -%}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'color'));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'tel'));

src/Symfony/Component/Form/Extension/Core/CoreExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ protected function loadTypes()
7777
new Type\SubmitType(),
7878
new Type\ResetType(),
7979
new Type\CurrencyType(),
80+
new Type\TelType(),
81+
new Type\ColorType(),
8082
);
8183
}
8284
}
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 ColorType extends AbstractType
17+
{
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
public function getParent()
22+
{
23+
return TextType::class;
24+
}
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function getBlockPrefix()
30+
{
31+
return 'color';
32+
}
33+
}
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 TelType extends AbstractType
17+
{
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
public function getParent()
22+
{
23+
return TextType::class;
24+
}
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function getBlockPrefix()
30+
{
31+
return 'tel';
32+
}
33+
}

src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,4 +2468,34 @@ public function testButtonAttributeNameRepeatedIfTrue()
24682468
// foo="foo"
24692469
$this->assertSame('<button type="button" id="button" name="button" foo="foo" class="btn-default btn">[trans]Button[/trans]</button>', $html);
24702470
}
2471+
2472+
public function testTel()
2473+
{
2474+
$tel = '0102030405';
2475+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TelType', $tel);
2476+
2477+
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
2478+
'/input
2479+
[@type="tel"]
2480+
[@name="name"]
2481+
[@class="my&class form-control"]
2482+
[@value="0102030405"]
2483+
'
2484+
);
2485+
}
2486+
2487+
public function testColor()
2488+
{
2489+
$color = '#0000ff';
2490+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ColorType', $color);
2491+
2492+
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
2493+
'/input
2494+
[@type="color"]
2495+
[@name="name"]
2496+
[@class="my&class form-control"]
2497+
[@value="#0000ff"]
2498+
'
2499+
);
2500+
}
24712501
}

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,4 +2463,32 @@ public function testAttributesNotTranslatedWhenTranslationDomainIsFalse()
24632463
$this->assertMatchesXpath($html, '/form//input[@title="Foo"]');
24642464
$this->assertMatchesXpath($html, '/form//input[@placeholder="Bar"]');
24652465
}
2466+
2467+
public function testTel()
2468+
{
2469+
$tel = '0102030405';
2470+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TelType', $tel);
2471+
2472+
$this->assertWidgetMatchesXpath($form->createView(), array(),
2473+
'/input
2474+
[@type="tel"]
2475+
[@name="name"]
2476+
[@value="0102030405"]
2477+
'
2478+
);
2479+
}
2480+
2481+
public function testColor()
2482+
{
2483+
$color = '#0000ff';
2484+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ColorType', $color);
2485+
2486+
$this->assertWidgetMatchesXpath($form->createView(), array(),
2487+
'/input
2488+
[@type="color"]
2489+
[@name="name"]
2490+
[@value="#0000ff"]
2491+
'
2492+
);
2493+
}
24662494
}

src/Symfony/Component/Form/Tests/Fixtures/Descriptor/defaults_1.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"Symfony\\Component\\Form\\Extension\\Core\\Type\\CheckboxType",
66
"Symfony\\Component\\Form\\Extension\\Core\\Type\\ChoiceType",
77
"Symfony\\Component\\Form\\Extension\\Core\\Type\\CollectionType",
8+
"Symfony\\Component\\Form\\Extension\\Core\\Type\\ColorType",
89
"Symfony\\Component\\Form\\Extension\\Core\\Type\\CountryType",
910
"Symfony\\Component\\Form\\Extension\\Core\\Type\\CurrencyType",
1011
"Symfony\\Component\\Form\\Extension\\Core\\Type\\DateIntervalType",
@@ -27,6 +28,7 @@
2728
"Symfony\\Component\\Form\\Extension\\Core\\Type\\ResetType",
2829
"Symfony\\Component\\Form\\Extension\\Core\\Type\\SearchType",
2930
"Symfony\\Component\\Form\\Extension\\Core\\Type\\SubmitType",
31+
"Symfony\\Component\\Form\\Extension\\Core\\Type\\TelType",
3032
"Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType",
3133
"Symfony\\Component\\Form\\Extension\\Core\\Type\\TextareaType",
3234
"Symfony\\Component\\Form\\Extension\\Core\\Type\\TimeType",

src/Symfony/Component/Form/Tests/Fixtures/Descriptor/defaults_1.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
----------------------------------------------------------------
44

55
BirthdayType, ButtonType, CheckboxType, ChoiceType, CollectionType
6-
CountryType, CurrencyType, DateIntervalType, DateTimeType, DateType
7-
EmailType, FileType, FormType, HiddenType, IntegerType
8-
LanguageType, LocaleType, MoneyType, NumberType, PasswordType
9-
PercentType, RadioType, RangeType, RepeatedType, ResetType
10-
SearchType, SubmitType, TextType, TextareaType, TimeType
11-
TimezoneType, UrlType
6+
ColorType, CountryType, CurrencyType, DateIntervalType, DateTimeType
7+
DateType, EmailType, FileType, FormType, HiddenType
8+
IntegerType, LanguageType, LocaleType, MoneyType, NumberType
9+
PasswordType, PercentType, RadioType, RangeType, RepeatedType
10+
ResetType, SearchType, SubmitType, TelType, TextType
11+
TextareaType, TimeType, TimezoneType, UrlType
1212

1313
Service form types
1414
------------------

src/Symfony/Component/Form/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
4040
"symfony/dependency-injection": "<3.3",
4141
"symfony/doctrine-bridge": "<2.7",
42-
"symfony/framework-bundle": "<2.7",
42+
"symfony/framework-bundle": "<3.4",
4343
"symfony/http-kernel": "<3.3.5",
44-
"symfony/twig-bridge": "<2.7"
44+
"symfony/twig-bridge": "<3.4"
4545
},
4646
"suggest": {
4747
"symfony/validator": "For form validation.",

0 commit comments

Comments
 (0)