bug #36869 [Form] don't add the inputmode attribute on fields whose type is the same (MatTheCat)

This PR was submitted for the master branch but it was merged into the 5.1 branch instead.

Discussion
----------

[Form] don't add the inputmode attribute on fields whose type is the same

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix https://github.com/symfony/symfony/pull/34986
| License       | MIT

These is no need to add the `inputmode` attribute on fields whose `type` is the same.

From https://html.spec.whatwg.org/multipage/interaction.html#attr-inputmode
> When inputmode is unspecified (or is in a state not supported by the user agent), the user agent should determine the default virtual keyboard to be shown. Contextual information such as the input type or pattern attributes should be used to determine which type of virtual keyboard should be presented to the user.

From https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode
> **tel**
> Inputs that *require* a telephone number should typically use `<input type="tel">` instead.

> **search**
> Inputs that *require* a search query should typically use `<input type="search">` instead.

> **email**
> Inputs that *require* email addresses should typically use `<input type="email">` instead.

As such there is no point in adding `inputmode` for those types.

Symfony’s `UrlType` uses `inputmode` **only** when the `type` has to be `text` because the `default_protocol` option is set.

Commits
-------

d933fa136f Revert https://github.com/symfony/symfony/pull/34986
This commit is contained in:
Fabien Potencier 2020-05-22 19:16:05 +02:00
commit a99a55ffe6
7 changed files with 0 additions and 139 deletions

View File

@ -12,7 +12,6 @@ CHANGELOG
* Added a `ChoiceList` facade to leverage explicit choice list caching based on options
* Added an `AbstractChoiceLoader` to simplify implementations and handle global optimizations
* The `view_timezone` option defaults to the `model_timezone` if no `reference_date` is configured.
* Added default `inputmode` attribute to Search, Email and Tel form types.
* Implementing the `FormConfigInterface` without implementing the `getIsEmptyCallback()` method
is deprecated. The method will be added to the interface in 6.0.
* Implementing the `FormConfigBuilderInterface` without implementing the `setIsEmptyCallback()` method

View File

@ -12,8 +12,6 @@
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
{
@ -25,14 +23,6 @@ class EmailType extends AbstractType
return TextType::class;
}
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['attr']['inputmode'] = $options['attr']['inputmode'] ?? 'email';
}
/**
* {@inheritdoc}
*/

View File

@ -12,8 +12,6 @@
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
{
@ -25,14 +23,6 @@ class SearchType extends AbstractType
return TextType::class;
}
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['attr']['inputmode'] = $options['attr']['inputmode'] ?? 'search';
}
/**
* {@inheritdoc}
*/

View File

@ -12,8 +12,6 @@
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
{
@ -25,14 +23,6 @@ class TelType extends AbstractType
return TextType::class;
}
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['attr']['inputmode'] = $options['attr']['inputmode'] ?? 'tel';
}
/**
* {@inheritdoc}
*/

View File

@ -1,36 +0,0 @@
<?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\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, '');
}
}

View File

@ -1,36 +0,0 @@
<?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\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, '');
}
}

View File

@ -1,36 +0,0 @@
<?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\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, '');
}
}