Skip to content

Commit a3ec370

Browse files
Merge branch '4.4' into 5.0
* 4.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 Allow invalidateTags calls to be traced by data collector [YAML] escape DEL(\x7f) fix compatibility with phpunit 9 [Cache] skip APCu in chains when the backend is disabled [Mailer] Add a comment to avoid more wrong PRs on this piece of code [Form] apply automatically step=1 for datetime-local input Fixing a bug where class_alias would cause incorrect items in debug:autowiring [DependencyInjection][ServiceSubscriber] Support late aliases
2 parents cb88f4a + 5052999 commit a3ec370

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
@@ -215,6 +215,14 @@ public function buildView(FormView $view, FormInterface $form, array $options)
215215
// * the html5 is set to true
216216
if ($options['html5'] && 'single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
217217
$view->vars['type'] = 'datetime-local';
218+
219+
// we need to force the browser to display the seconds by
220+
// adding the HTML attribute step if not already defined.
221+
// Otherwise the browser will not display and so not send the seconds
222+
// therefore the value will always be considered as invalid.
223+
if ($options['with_seconds'] && !isset($view->vars['attr']['step'])) {
224+
$view->vars['attr']['step'] = 1;
225+
}
218226
}
219227
}
220228

Tests/Extension/Core/Type/DateTimeTypeTest.php

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

485+
public function testSingleTextWidgetWithSecondsShouldHaveRightStepAttribute()
486+
{
487+
$view = $this->factory
488+
->create(static::TESTED_TYPE, null, [
489+
'widget' => 'single_text',
490+
'with_seconds' => true,
491+
])
492+
->createView()
493+
;
494+
495+
$this->assertArrayHasKey('step', $view->vars['attr']);
496+
$this->assertEquals(1, $view->vars['attr']['step']);
497+
}
498+
499+
public function testSingleTextWidgetWithSecondsShouldNotOverrideStepAttribute()
500+
{
501+
$view = $this->factory
502+
->create(static::TESTED_TYPE, null, [
503+
'widget' => 'single_text',
504+
'with_seconds' => true,
505+
'attr' => [
506+
'step' => 30,
507+
],
508+
])
509+
->createView()
510+
;
511+
512+
$this->assertArrayHasKey('step', $view->vars['attr']);
513+
$this->assertEquals(30, $view->vars['attr']['step']);
514+
}
515+
485516
public function testSingleTextWidgetWithCustomNonHtml5Format()
486517
{
487518
$form = $this->factory->create(static::TESTED_TYPE, new \DateTime('2019-02-13 19:12:13'), [

0 commit comments

Comments
 (0)