8000 [Form] Added default `inputmode` attribute to Search, Email and Tel form types by fre5h · Pull Request #34986 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

5.1.0
-----

* Added default `inputmode` attribute to Search, Email and Tel form types.

5.0.0
-----

Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Form/Extension/Core/Type/EmailType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -23,6 +25,14 @@ public function getParent()
return __NAMESPACE__.'\TextType';
}

/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['attr']['inputmode'] = $options['attr']['inputmode'] ?? 'email';
}

/**
* {@inheritdoc}
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Form/Extension/Core/Type/SearchType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -23,6 +25,14 @@ public function getParent()
return __NAMESPACE__.'\TextType';
}

/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['attr']['inputmode'] = $options['attr']['inputmode'] ?? 'search';
}

/**
* {@inheritdoc}
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Form/Extension/Core/Type/TelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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, '');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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, '');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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, '');
}
}
0