Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[TwigBridge] Allow floats in html5 input type number field
  • Loading branch information
wimhendrikx authored and nicolas-grekas committed Feb 23, 2023
commit a6f2bcd01961168c2a26ddde7db861714871b434
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,25 @@ public function testRenderNumberWithHtml5NumberType()
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
'/input
[@type="number"]
[@step="any"]
[@name="name"]
[@class="my&class form-control"]
[@value="1234.56"]
'
);
}

public function testRenderNumberWithHtml5NumberTypeAndStepAttribute()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\NumberType', 1234.56, [
'html5' => true,
'attr' => ['step' => '0.1'],
]);

$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
'/input
[@type="number"]
[@step="0.1"]
[@name="name"]
[@class="my&class form-control"]
[@value="1234.56"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function buildView(FormView $view, FormInterface $form, array $options)
{
if ($options['html5']) {
$view->vars['type'] = 'number';

if (!isset($view->vars['attr']['step'])) {
$view->vars['attr']['step'] = 'any';
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions src/Symfony/Component/Form/Tests/AbstractLayoutTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,26 @@ public function testRenderNumberWithHtml5NumberType()
$this->assertWidgetMatchesXpath($form->createView(), [],
'/input
[@type="number"]
[@step="any"]
[@name="name"]
[@value="1234.56"]
'
);
}

public function testRenderNumberWithHtml5NumberTypeAndStepAttribute()
{
$this->requiresFeatureSet(403);

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\NumberType', 1234.56, [
'html5' => true,
'attr' => ['step' => '0.1'],
]);

$this->assertWidgetMatchesXpath($form->createView(), [],
'/input
[@type="number"]
[@step="0.1"]
[@name="name"]
[@value="1234.56"]
'
Expand Down