Skip to content

Commit

Permalink
bug #30061 [Form] render integer types with grouping as text input (x…
Browse files Browse the repository at this point in the history
…abbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[Form] render integer types with grouping as text input

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29422
| License       | MIT
| Doc PR        |

Commits
-------

d6a5fde render integer types with grouping as text input
  • Loading branch information
nicolas-grekas committed Feb 8, 2019
2 parents eb2a18e + d6a5fde commit f331c54
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
Expand Up @@ -1863,6 +1863,22 @@ public function testInteger()
);
}

public function testIntegerTypeWithGroupingRendersAsTextInput()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\IntegerType', 123, [
'grouping' => true,
]);

$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
'/input
[@type="text"]
[@name="name"]
[@class="my&class form-control"]
[@value="123"]
'
);
}

public function testLanguage()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\LanguageType', 'de');
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/composer.json
Expand Up @@ -23,7 +23,7 @@
"symfony/asset": "~2.8|~3.0|~4.0",
"symfony/dependency-injection": "~2.8|~3.0|~4.0",
"symfony/finder": "~2.8|~3.0|~4.0",
"symfony/form": "^3.4.22|~4.1.11|^4.2.3",
"symfony/form": "^3.4.23|^4.2.4",
"symfony/http-foundation": "^3.3.11|~4.0",
"symfony/http-kernel": "~3.2|~4.0",
"symfony/polyfill-intl-icu": "~1.0",
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/Form/Extension/Core/Type/IntegerType.php
Expand Up @@ -14,6 +14,8 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;

class IntegerType extends AbstractType
Expand All @@ -31,6 +33,16 @@ public function buildForm(FormBuilderInterface $builder, array $options)
));
}

/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
if ($options['grouping']) {
$view->vars['type'] = 'text';
}
}

/**
* {@inheritdoc}
*/
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Expand Up @@ -1730,6 +1730,21 @@ public function testInteger()
);
}

public function testIntegerTypeWithGroupingRendersAsTextInput()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\IntegerType', 123, [
'grouping' => true,
]);

$this->assertWidgetMatchesXpath($form->createView(), [],
'/input
[@type="text"]
[@name="name"]
[@value="123"]
'
);
}

public function testLanguage()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\LanguageType', 'de');
Expand Down

0 comments on commit f331c54

Please sign in to comment.