8000 [Form] Change datetime to datetime-local for HTML5 datetime input by pierredup · Pull Request #24401 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Change datetime to datetime-local for HTML5 datetime input #24401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2018
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
13 changes: 4 additions & 9 deletions src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,12 @@ class DateTimeType extends AbstractType

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@ public function testDateTimeWithWidgetSingleText()

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

$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
'/input
[@type="datetime"]
[@type="datetime-local"]
[@name="name"]
[@class="my&class form-control"]
[@value="2011-02-03T04:05:06Z"]
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ public function testDateTimeWithWidgetSingleText()

$this->assertWidgetMatchesXpath($form->createVi 8000 ew(), array(),
'/input
[@type="datetime"]
[@type="datetime-local"]
[@name="name"]
[@value="2011-02-03T04:05:06Z"]
'
Expand All @@ -1446,7 +1446,7 @@ public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()

$this->assertWidgetMatchesXpath($form->createView(), array(),
'/input
[@type="datetime"]
[@type="datetime-local"]
[@name="name"]
[@value="2011-02-03T04:05:06Z"]
'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function testSingleTextWidgetShouldUseTheRightInputType()
))
->createView();

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

public function testPassDefaultPlaceholderToViewIfNotRequired()
Expand Down Expand Up @@ -433,7 +433,7 @@ public function testPassHtml5TypeIfSingleTextAndHtml5Format()
))
->createView();

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

public function testDontPassHtml5TypeIfHtml5NotAllowed()
Expand Down
0