Skip to content

Commit 008a7b3

Browse files
Merge branch '6.4' into 7.3
* 6.4: Handle signals on text input [TwigBridge] Fix form constraint [Runtime] Reuse the already created Request object when the app needs it as argument returns a kernel Update validators.el.xlf Fix MoneyType: add missing step attribute when html5=true [Console] Preserve `--help` option when a command is not found [Messenger] Fix PHP 8.5 deprecation for pgsqlGetNotify() in PostgreSQL transport chore: PHP CS Fixer - do not use deprecated sets in config verify spanish translations with state needs-review-translation
2 parents a8f32aa + e6378bc commit 008a7b3

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Extension/Core/Type/MoneyType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public function buildView(FormView $view, FormInterface $form, array $options):
5151

5252
if ($options['html5']) {
5353
$view->vars['type'] = 'number';
54+
55+
if (!isset($view->vars['attr']['step'])) {
56+
$view->vars['attr']['step'] = 'any';
57+
}
58+
} else {
59+
$view->vars['attr']['inputmode'] = 0 === $options['scale'] ? 'numeric' : 'decimal';
5460
}
5561
}
5662

Tests/Extension/Core/Type/MoneyTypeTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,46 @@ public function testHtml5EnablesSpecificFormatting()
124124
$this->assertSame('number', $form->createView()->vars['type']);
125125
}
126126

127+
public function testHtml5AddsStepAttributeIfNotSet()
128+
{
129+
$form = $this->factory->create(static::TESTED_TYPE, null, [
130+
'html5' => true,
131+
]);
132+
$view = $form->createView();
133+
$this->assertSame('any', $view->vars['attr']['step']);
134+
135+
$form = $this->factory->create(static::TESTED_TYPE, null, [
136+
'html5' => false,
137+
'scale' => 2,
138+
]);
139+
$view = $form->createView();
140+
$this->assertSame('decimal', $view->vars['attr']['inputmode']);
141+
142+
$form = $this->factory->create(static::TESTED_TYPE, null, [
143+
'html5' => false,
144+
'scale' => 0,
145+
]);
146+
$view = $form->createView();
147+
$this->assertSame('numeric', $view->vars['attr']['inputmode']);
148+
}
149+
150+
public function testHtml5DoesNotOverrideUserProvidedStep()
151+
{
152+
$form = $this->factory->create(static::TESTED_TYPE, null, [
153+
'html5' => true,
154+
'attr' => ['step' => '0.01'],
155+
]);
156+
$view = $form->createView();
157+
$this->assertSame('0.01', $view->vars['attr']['step']);
158+
159+
$form = $this->factory->create(static::TESTED_TYPE, null, [
160+
'html5' => false,
161+
'scale' => 2,
162+
]);
163+
$view = $form->createView();
164+
$this->assertSame('decimal', $view->vars['attr']['inputmode']);
165+
}
166+
127167
public function testDefaultInput()
128168
{
129169
$form = $this->factory->create(static::TESTED_TYPE, null, ['divisor' => 100]);

0 commit comments

Comments
 (0)