8000 [Form] Added default `inputmode` attribute to Search, Email and Tel f… · symfony/symfony@dbc500f · GitHub
[go: up one dir, main page]

Skip to content

Commit dbc500f

Browse files
fre5hnicolas-grekas
authored andcommitted
[Form] Added default inputmode attribute to Search, Email and Tel form types
1 parent 8c80c5b commit dbc500f

File tree

7 files changed

+143
-0
lines changed

7 files changed

+143
-0
lines changed

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.1.0
5+
-----
6+
7+
* Added default `inputmode` attribute to Search, Email and Tel form types.
8+
49
5.0.0
510
-----
611

src/Symfony/Component/Form/Extension/Core/Type/EmailType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15+
use Symfony\Component\Form\FormInterface;
16+
use Symfony\Component\Form\FormView;
1517

1618
class EmailType extends AbstractType
1719
{
@@ -23,6 +25,14 @@ public function getParent()
2325
return __NAMESPACE__.'\TextType';
2426
}
2527

28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function buildView(FormView $view, FormInterface $form, array $options)
32+
{
33+
$view->vars['attr']['inputmode'] = $options['attr']['inputmode'] ?? 'email';
34+
}
35+
2636
/**
2737
* {@inheritdoc}
2838
*/

src/Symfony/Component/Form/Extension/Core/Type/SearchType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15+
use Symfony\Component\Form\FormInterface;
16+
use Symfony\Component\Form\FormView;
1517

1618
class SearchType extends AbstractType
1719
{
@@ -23,6 +25,14 @@ public function getParent()
2325
return __NAMESPACE__.'\TextType';
2426
}
2527

28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function buildView(FormView $view, FormInterface $form, array $options)
32+
{
33+
$view->vars['attr']['inputmode'] = $options['attr']['inputmode'] ?? 'search';
34+
}
35+
2636
/**
2737
* {@inheritdoc}
2838
*/

src/Symfony/Component/Form/Extension/Core/Type/TelType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15+
use Symfony\Component\Form\FormInterface;
16+
use Symfony\Component\Form\FormView;
1517

1618
class TelType extends AbstractType
1719
{
@@ -23,6 +25,14 @@ public function getParent()
2325
return TextType::class;
2426
}
2527

28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function buildView(FormView $view, FormInterface $form, array $options)
32+
{
33+
$view->vars['attr']['inputmode'] = $options['attr']['inputmode'] ?? 'tel';
34+
}
35+
2636
/**
2737
* {@inheritdoc}
2838
*/
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Tests\Extension\Core\Type;
13+
14+
class EmailTypeTest extends BaseTypeTest
15+
{
16+
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\EmailType';
17+
18+
public function testDefaultInputmode()
19+
{
20+
$form = $this->factory->create(static::TESTED_TYPE);
21+
22+
$this->assertSame('email', $form->createView()->vars['attr']['inputmode']);
23+
}
24+
25+
public function testOverwrittenInputmode()
26+
{
27+
$form = $this->factory->create(static::TESTED_TYPE, null, ['attr' => ['inputmode' => 'text']]);
28+
29+
$this->assertSame('text', $form->createView()->vars['attr']['inputmode']);
30+
}
31+
32+
public function testSubmitNull($expected = null, $norm = null, $view = null)
33+
{
34+
parent::testSubmitNull($expected, $norm, '');
35+
}
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Tests\Extension\Core\Type;
13+
14+
class SearchTypeTest extends BaseTypeTest
15+
{
16+
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\SearchType';
17+
18+
public function testDefaultInputmode()
19+
{
20+
$form = $this->factory->create(static::TESTED_TYPE);
21+
22+
$this->assertSame('search', $form->createView()->vars['attr']['inputmode']);
23+
}
24+
25+
public function testOverwrittenInputmode()
26+
{
27+
$form = $this->factory->create(static::TESTED_TYPE, null, ['attr' => ['inputmode' => 'text']]);
28+
29+
$this->assertSame('text', $form->createView()->vars['attr']['inputmode']);
30+
}
31+
32+
public function testSubmitNull($expected = null, $norm = null, $view = null)
33+
{
34+
parent::testSubmitNull($expected, $norm, '');
35+
}
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Tests\Extension\Core\Type;
13+
14+
class TelTypeTest extends BaseTypeTest
15+
{
16+
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\TelType';
17+
18+
public function testDefaultInputmode()
19+
{
20+
$form = $this->factory->create(static::TESTED_TYPE);
21+
22+
$this->assertSame('tel', $form->createView()->vars['attr']['inputmode']);
23+
}
24+
25+
public function testOverwrittenInputmode()
26+
{
27+
$form = $this->factory->create(static::TESTED_TYPE, null, ['attr' => ['inputmode' => 'text']]);
28+
29+
$this->assertSame('text', $form->createView()->vars['attr']['inputmode']);
30+
}
31+
32+
public function testSubmitNull($expected = null, $norm = null, $view = null)
33+
{
34+
parent::testSubmitNull($expected, $norm, '');
35+
}
36+
}

0 commit comments

Comments
 (0)
0