Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0877bf6

Browse filesBrowse files
committed
bug #24401 [Form] Change datetime to datetime-local for HTML5 datetime input (pierredup)
This PR was merged into the 2.7 branch. Discussion ---------- [Form] Change datetime to datetime-local for HTML5 datetime input | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | Unknown | Deprecations? | no | Tests pass? | yes | Fixed tickets | #24307 | License | MIT | Doc PR | N/A Change the input type from datetime to datetime-local for HTML5 date input (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime) Commits ------- 802c67c Change datetime input to datetime-local
2 parents 019590d + 802c67c commit 0877bf6
Copy full SHA for 0877bf6

File tree

4 files changed

+10
-15
lines changed
Filter options

4 files changed

+10
-15
lines changed

‎src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php
+4-9Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,12 @@ class DateTimeType extends AbstractType
3434

3535
/**
3636
* This is not quite the HTML5 format yet, because ICU lacks the
37-
* capability of parsing and generating RFC 3339 dates, which
38-
* are like the below pattern but with a timezone suffix. The
39-
* timezone suffix is.
40-
*
41-
* * "Z" for UTC
42-
* * "(-|+)HH:mm" for other timezones (note the colon!)
37+
* capability of parsing and generating RFC 3339 dates.
4338
*
4439
* For more information see:
4540
*
4641
* http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax
47-
* http://www.w3.org/TR/html-markup/input.datetime.html
42+
* https://www.w3.org/TR/html5/sec-forms.html#local-date-and-time-state-typedatetimelocal
4843
* http://tools.ietf.org/html/rfc3339
4944
*
5045
* An ICU ticket was created:
@@ -54,7 +49,7 @@ class DateTimeType extends AbstractType
5449
* yet. To temporarily circumvent this issue, DateTimeToRfc3339Transformer
5550
* is used when the format matches this constant.
5651
*/
57-
const HTML5_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZZZZZ";
52+
const HTML5_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
5853

5954
private static $acceptedFormats = array(
6055
\IntlDateFormatter::FULL,
@@ -192,7 +187,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
192187
// * the format matches the one expected by HTML5
193188
// * the html5 is set to true
194189
if ($options['html5'] && 'single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
195-
$view->vars['type'] = 'datetime';
190+
$view->vars['type'] = 'datetime-local';
196191
}
197192
}
198193

‎src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ public function testDateTimeWithWidgetSingleText()
15251525

15261526
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
15271527
'/input
1528-
[@type="datetime"]
1528+
[@type="datetime-local"]
15291529
[@name="name"]
15301530
[@class="my&class form-control"]
15311531
[@value="2011-02-03T04:05:06Z"]
@@ -1546,7 +1546,7 @@ public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
15461546

15471547
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
15481548
'/input
1549-
[@type="datetime"]
1549+
[@type="datetime-local"]
15501550
[@name="name"]
15511551
[@class="my&class form-control"]
15521552
[@value="2011-02-03T04:05:06Z"]

‎src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ public function testDateTimeWithWidgetSingleText()
14261426

14271427
$this->assertWidgetMatchesXpath($form->createView(), array(),
14281428
'/input
1429-
[@type="datetime"]
1429+
[@type="datetime-local"]
14301430
[@name="name"]
14311431
[@value="2011-02-03T04:05:06Z"]
14321432
'
@@ -1446,7 +1446,7 @@ public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
14461446

14471447
$this->assertWidgetMatchesXpath($form->createView(), array(),
14481448
'/input
1449-
[@type="datetime"]
1449+
[@type="datetime-local"]
14501450
[@name="name"]
14511451
[@value="2011-02-03T04:05:06Z"]
14521452
'

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function testSingleTextWidgetShouldUseTheRightInputType()
283283
))
284284
->createView();
285285

286-
$this->assertEquals('datetime', $view->vars['type']);
286+
$this->assertEquals('datetime-local', $view->vars['type']);
287287
}
288288

289289
public function testPassDefaultPlaceholderToViewIfNotRequired()
@@ -433,7 +433,7 @@ public function testPassHtml5TypeIfSingleTextAndHtml5Format()
433433
))
434434
->createView();
435435

436-
$this->assertSame('datetime', $view->vars['type']);
436+
$this->assertSame('datetime-local', $view->vars['type']);
437437
}
438438

439439
public function testDontPassHtml5TypeIfHtml5NotAllowed()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.