diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 1f0121d2aa21..6b207848dc76 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +5.1.0 +----- + + * Added default `inputmode` attribute to Search, Email and Tel form types. + 5.0.0 ----- diff --git a/src/Symfony/Component/Form/Extension/Core/Type/EmailType.php b/src/Symfony/Component/Form/Extension/Core/Type/EmailType.php index 1bc1019ab9f2..b5e7a6de36aa 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/EmailType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/EmailType.php @@ -12,6 +12,8 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\Form\FormView; class EmailType extends AbstractType { @@ -23,6 +25,14 @@ public function getParent() return TextType::class; } + /** + * {@inheritdoc} + */ + public function buildView(FormView $view, FormInterface $form, array $options) + { + $view->vars['attr']['inputmode'] = $options['attr']['inputmode'] ?? 'email'; + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Form/Extension/Core/Type/SearchType.php b/src/Symfony/Component/Form/Extension/Core/Type/SearchType.php index c817a26d025b..94ffffa5e667 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/SearchType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/SearchType.php @@ -12,6 +12,8 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\Form\FormView; class SearchType extends AbstractType { @@ -23,6 +25,14 @@ public function getParent() return TextType::class; } + /** + * {@inheritdoc} + */ + public function buildView(FormView $view, FormInterface $form, array $options) + { + $view->vars['attr']['inputmode'] = $options['attr']['inputmode'] ?? 'search'; + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TelType.php b/src/Symfony/Component/Form/Extension/Core/Type/TelType.php index de74a3ed3721..535dba8e1093 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TelType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TelType.php @@ -12,6 +12,8 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\Form\FormView; class TelType extends AbstractType { @@ -23,6 +25,14 @@ public function getParent() return TextType::class; } + /** + * {@inheritdoc} + */ + public function buildView(FormView $view, FormInterface $form, array $options) + { + $view->vars['attr']['inputmode'] = $options['attr']['inputmode'] ?? 'tel'; + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/EmailTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/EmailTypeTest.php new file mode 100644 index 000000000000..159c51d44aba --- /dev/null +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/EmailTypeTest.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Extension\Core\Type; + +class EmailTypeTest extends BaseTypeTest +{ + const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\EmailType'; + + public function testDefaultInputmode() + { + $form = $this->factory->create(static::TESTED_TYPE); + + $this->assertSame('email', $form->createView()->vars['attr']['inputmode']); + } + + public function testOverwrittenInputmode() + { + $form = $this->factory->create(static::TESTED_TYPE, null, ['attr' => ['inputmode' => 'text']]); + + $this->assertSame('text', $form->createView()->vars['attr']['inputmode']); + } + + public function testSubmitNull($expected = null, $norm = null, $view = null) + { + parent::testSubmitNull($expected, $norm, ''); + } +} diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/SearchTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/SearchTypeTest.php new file mode 100644 index 000000000000..101b02dab733 --- /dev/null +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/SearchTypeTest.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Extension\Core\Type; + +class SearchTypeTest extends BaseTypeTest +{ + const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\SearchType'; + + public function testDefaultInputmode() + { + $form = $this->factory->create(static::TESTED_TYPE); + + $this->assertSame('search', $form->createView()->vars['attr']['inputmode']); + } + + public function testOverwrittenInputmode() + { + $form = $this->factory->create(static::TESTED_TYPE, null, ['attr' => ['inputmode' => 'text']]); + + $this->assertSame('text', $form->createView()->vars['attr']['inputmode']); + } + + public function testSubmitNull($expected = null, $norm = null, $view = null) + { + parent::testSubmitNull($expected, $norm, ''); + } +} diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TelTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TelTypeTest.php new file mode 100644 index 000000000000..a72bd11c6f51 --- /dev/null +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TelTypeTest.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Extension\Core\Type; + +class TelTypeTest extends BaseTypeTest +{ + const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\TelType'; + + public function testDefaultInputmode() + { + $form = $this->factory->create(static::TESTED_TYPE); + + $this->assertSame('tel', $form->createView()->vars['attr']['inputmode']); + } + + public function testOverwrittenInputmode() + { + $form = $this->factory->create(static::TESTED_TYPE, null, ['attr' => ['inputmode' => 'text']]); + + $this->assertSame('text', $form->createView()->vars['attr']['inputmode']); + } + + public function testSubmitNull($expected = null, $norm = null, $view = null) + { + parent::testSubmitNull($expected, $norm, ''); + } +}