8000 feature #45101 [Form] Add inputmode attribute on NumberType (welcoMat… · symfony/symfony@1ebb5d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ebb5d9

Browse files
committed
feature #45101 [Form] Add inputmode attribute on NumberType (welcoMattic)
This PR was merged into the 6.1 branch. Discussion ---------- [Form] Add inputmode attribute on NumberType | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #45099 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Quick add of `inputmode` attribute on NumberType, let's discuss about this: - Should it be the default? - Should we add a way to not add the attribute? Thank you @GromNaN for the issue, I had this idea in mind for a long time 😉 Commits ------- f71213b Add inputmode attribute on NumberType
2 parents 86a7f94 + f71213b commit 1ebb5d9

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/Symfony/Component/Form/Extension/Core/Type/NumberType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public function buildView(FormView $view, FormInterface $form, array $options)
4747
{
4848
if ($options['html5']) {
4949
$view->vars['type'] = 'number';
50+
} else {
51+
$view->vars['attr']['inputmode'] = 0 === $options['scale'] ? 'numeric' : 'decimal';
5052
}
5153
}
5254

src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,36 @@ public function testGroupingNotAllowedWithHtml5Widget()
202202
'html5' => true,
203203
]);
204204
}
205+
206+
public function testNumericInputmode()
207+
{
208+
$form = $this->factory->create(static::TESTED_TYPE, null, [
209+
'scale' => 0,
210+
'html5' => false,
211+
]);
212+
$form->setData(12345.54321);
213+
214+
$this->assertSame('numeric', $form->createView()->vars['attr']['inputmode']);
215+
}
216+
217+
public function testDecimalInputmode()
218+
{
219+
$form = $this->factory->create(static::TESTED_TYPE, null, [
220+
'scale' => 2,
221+
'html5' => false,
222+
]);
223+
$form->setData(12345.54321);
224+
225+
$this->assertSame('decimal', $form->createView()->vars['attr']['inputmode']);
226+
}
227+
228+
public function testNoInputmodeWithHtml5Widget()
229+
{
230+
$form = $this->factory->create(static::TESTED_TYPE, null, [
231+
'html5' => true,
232+
]);
233+
$form->setData(12345.54321);
234+
235+
$this->assertArrayNotHasKey('inputmode', $form->createView()->vars['attr']);
236+
}
205237
}

0 commit comments

Comments
 (0)
0