Skip to content

Commit 91f38a6

Browse files
committed
render integer types with grouping as text input
1 parent 92458da commit 91f38a6

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Extension/Core/Type/IntegerType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Form\AbstractType;
1515
use Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer;
1616
use Symfony\Component\Form\FormBuilderInterface;
17+
use Symfony\Component\Form\FormInterface;
18+
use Symfony\Component\Form\FormView;
1719
use Symfony\Component\OptionsResolver\OptionsResolver;
1820

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

36+
/**
37+
* {@inheritdoc}
38+
*/
39+
public function buildView(FormView $view, FormInterface $form, array $options)
40+
{
41+
if ($options['grouping']) {
42+
$view->vars['type'] = 'text';
43+
}
44+
}
45+
3446
/**
3547
* {@inheritdoc}
3648
*/

Tests/AbstractLayoutTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,21 @@ public function testInteger()
17301730
);
17311731
}
17321732

1733+
public function testIntegerTypeWithGroupingRendersAsTextInput()
1734+
{
1735+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\IntegerType', 123, [
1736+
'grouping' => true,
1737+
]);
1738+
1739+
$this->assertWidgetMatchesXpath($form->createView(), [],
1740+
'/input
1741+
[@type="text"]
1742+
[@name="name"]
1743+
[@value="123"]
1744+
'
1745+
);
1746+
}
1747+
17331748
public function testLanguage()
17341749
{
17351750
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\LanguageType', 'de');

0 commit comments

Comments
 (0)