Skip to content

Commit 5047fe3

Browse files
committed
feature #30267 [Form] add option to render NumberType as type="number" (xabbuh)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Form] add option to render NumberType as type="number" | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8106 | License | MIT | Doc PR | symfony/symfony-docs#10997 Commits ------- 42e8f5e3a2 add option to render NumberType as type="number"
2 parents 6157b91 + 4bcee9d commit 5047fe3

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Resources/views/Form/form_div_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
{%- endblock dateinterval_widget -%}
171171

172172
{%- block number_widget -%}
173-
{# type="number" doesn't work with floats #}
173+
{# type="number" doesn't work with floats in localized formats #}
174174
{%- set type = type|default('text') -%}
175175
{{ block('form_widget_simple') }}
176176
{%- endblock number_widget -%}

Tests/Extension/AbstractBootstrap3LayoutTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,22 @@ public function testNumber()
20892089
);
20902090
}
20912091

2092+
public function testRenderNumberWithHtml5NumberType()
2093+
{
2094+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\NumberType', 1234.56, [
2095+
'html5' => true,
2096+
]);
2097+
2098+
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
2099+
'/input
2100+
[@type="number"]
2101+
[@name="name"]
2102+
[@class="my&class form-control"]
2103+
[@value="1234.56"]
2104+
'
2105+
);
2106+
}
2107+
20922108
public function testPassword()
20932109
{
20942110
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PasswordType', 'foo&bar');

0 commit comments

Comments
 (0)