Skip to content

Commit 4bcee9d

Browse files
committed
add option to render NumberType as type="number"
1 parent 6ba351a commit 4bcee9d

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)