[Form] apply automatically step=1 for datetime-local input
This commit is contained in:
parent
08ded7fed6
commit
3c24cfecdd
@ -203,6 +203,14 @@ class DateTimeType extends AbstractType
|
|||||||
// * the html5 is set to true
|
// * the html5 is set to true
|
||||||
if ($options['html5'] && 'single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
|
if ($options['html5'] && 'single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
|
||||||
$view->vars['type'] = 'datetime-local';
|
$view->vars['type'] = 'datetime-local';
|
||||||
|
|
||||||
|
// we need to force the browser to display the seconds by
|
||||||
|
// adding the HTML attribute step if not already defined.
|
||||||
|
// Otherwise the browser will not display and so not send the seconds
|
||||||
|
// therefore the value will always be considered as invalid.
|
||||||
|
if ($options['with_seconds'] && !isset($view->vars['attr']['step'])) {
|
||||||
|
$view->vars['attr']['step'] = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,6 +444,37 @@ class DateTimeTypeTest extends BaseTypeTest
|
|||||||
$this->assertArrayNotHasKey('type', $view->vars);
|
$this->assertArrayNotHasKey('type', $view->vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSingleTextWidgetWithSecondsShouldHaveRightStepAttribute()
|
||||||
|
{
|
||||||
|
$view = $this->factory
|
||||||
|
->create(static::TESTED_TYPE, null, [
|
||||||
|
'widget' => 'single_text',
|
||||||
|
'with_seconds' => true,
|
||||||
|
])
|
||||||
|
->createView()
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('step', $view->vars['attr']);
|
||||||
|
$this->assertEquals(1, $view->vars['attr']['step']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSingleTextWidgetWithSecondsShouldNotOverrideStepAttribute()
|
||||||
|
{
|
||||||
|
$view = $this->factory
|
||||||
|
->create(static::TESTED_TYPE, null, [
|
||||||
|
'widget' => 'single_text',
|
||||||
|
'with_seconds' => true,
|
||||||
|
'attr' => [
|
||||||
|
'step' => 30,
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->createView()
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('step', $view->vars['attr']);
|
||||||
|
$this->assertEquals(30, $view->vars['attr']['step']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testDateTypeChoiceErrorsBubbleUp()
|
public function testDateTypeChoiceErrorsBubbleUp()
|
||||||
{
|
{
|
||||||
$error = new FormError('Invalid!');
|
$error = new FormError('Invalid!');
|
||||||
|
Reference in New Issue
Block a user