Skip to content

Commit 5052999

Browse files
Merge branch '3.4' into 4.4
* 3.4: updated VERSION for 3.4.40 update CONTRIBUTORS for 3.4.40 updated CHANGELOG for 3.4.40 [WebProfilerBundle] changed label of peak memory usage in the time & memory panels (MB into MiB) add tests for the ConstraintViolationBuilder class Improve dirname usage [PhpUnitBridge] Use COMPOSER_BINARY env var if available [YAML] escape DEL(\x7f) fix compatibility with phpunit 9 [Cache] skip APCu in chains when the backend is disabled [Form] apply automatically step=1 for datetime-local input
2 parents 4cf3944 + 3aa9788 commit 5052999

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Extension/Core/Type/DateTimeType.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ public function buildView(FormView $view, FormInterface $form, array $options)
218218
// * the html5 is set to true
219219
if ($options['html5'] && 'single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
220220
$view->vars['type'] = 'datetime-local';
221+
222+
// we need to force the browser to display the seconds by
223+
// adding the HTML attribute step if not already defined.
224+
// Otherwise the browser will not display and so not send the seconds
225+
// therefore the value will always be considered as invalid.
226+
if ($options['with_seconds'] && !isset($view->vars['attr']['step'])) {
227+
$view->vars['attr']['step'] = 1;
228+
}
221229
}
222230
}
223231

Tests/Extension/Core/Type/DateTimeTypeTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,37 @@ public function testDontPassHtml5TypeIfNotSingleText()
495495
$this->assertArrayNotHasKey('type', $view->vars);
496496
}
497497

498+
public function testSingleTextWidgetWithSecondsShouldHaveRightStepAttribute()
499+
{
500+
$view = $this->factory
501+
->create(static::TESTED_TYPE, null, [
502+
'widget' => 'single_text',
503+
'with_seconds' => true,
504+
])
505+
->createView()
506+
;
507+
508+
$this->assertArrayHasKey('step', $view->vars['attr']);
509+
$this->assertEquals(1, $view->vars['attr']['step']);
510+
}
511+
512+
public function testSingleTextWidgetWithSecondsShouldNotOverrideStepAttribute()
513+
{
514+
$view = $this->factory
515+
->create(static::TESTED_TYPE, null, [
516+
'widget' => 'single_text',
517+
'with_seconds' => true,
518+
'attr' => [
519+
'step' => 30,
520+
],
521+
])
522+
->createView()
523+
;
524+
525+
$this->assertArrayHasKey('step', $view->vars['attr']);
526+
$this->assertEquals(30, $view->vars['attr']['step']);
527+
}
528+
498529
public function testSingleTextWidgetWithCustomNonHtml5Format()
499530
{
500531
$form = $this->factory->create(static::TESTED_TYPE, new \DateTime('2019-02-13 19:12:13'), [

0 commit comments

Comments
 (0)