[Form] Add tel and color types
This commit is contained in:
parent
f86b4c43a3
commit
5b07ca7f2f
@ -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 -%}
|
||||
|
@ -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'));
|
@ -77,6 +77,8 @@ class CoreExtension extends AbstractExtension
|
||||
new Type\SubmitType(),
|
||||
new Type\ResetType(),
|
||||
new Type\CurrencyType(),
|
||||
new Type\TelType(),
|
||||
new Type\ColorType(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
33
src/Symfony/Component/Form/Extension/Core/Type/ColorType.php
Normal file
33
src/Symfony/Component/Form/Extension/Core/Type/ColorType.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 ColorType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return TextType::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'color';
|
||||
}
|
||||
}
|
33
src/Symfony/Component/Form/Extension/Core/Type/TelType.php
Normal file
33
src/Symfony/Component/Form/Extension/Core/Type/TelType.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 TelType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return TextType::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'tel';
|
||||
}
|
||||
}
|
@ -2468,4 +2468,34 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
// 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"]
|
||||
'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2463,4 +2463,32 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
|
||||
$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"]
|
||||
'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
@ -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",
|
||||
|
@ -3,12 +3,12 @@
|
||||
[33m----------------------------------------------------------------[39m
|
||||
|
||||
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
|
||||
|
||||
[33mService form types[39m
|
||||
[33m------------------[39m
|
||||
|
@ -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.",
|
||||
|
Reference in New Issue
Block a user