-
Notifications
You must be signed in to change notification settings - Fork 824
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
HTML5 Date Fields #6766
HTML5 Date Fields #6766
Conversation
src/Forms/DateField.php
Outdated
@@ -226,8 +222,20 @@ protected function getFormatter() | |||
IntlDateFormatter::NONE | |||
); | |||
|
|||
// Don't invoke getDateFormat() directly to avoid infinite loop | |||
if ($this->dateFormat) { | |||
$isoFormat = 'y-MM-dd'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DBDate::ISO_DATE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh I was looking for a ICU constant for this but couldn't find it - good call!
src/Forms/DateField.php
Outdated
* | ||
* @var bool | ||
*/ | ||
protected $html5 = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we set this to true by default? In most cases it'll be more useful than a textfield right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm yeah I guess for most frontend implementations, it'll be a better default (opt-out of HTML5 rather than opt-in). For the CMS, it'll definitely be a better default, since we have a polyfill there. And it would save devs remembering that when writing getCMSFields()
. I'll change it, and update the changelog
src/Forms/DateField.php
Outdated
$clientView->onBeforeRender(); | ||
if ($this->getHTML5()) { | ||
// Browsers expect ISO 8601 dates, localisation is handled on the client | ||
$this->setDateFormat('y-MM-dd'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of modifying the state on render, can we move this logic to getDateFormat()? I realise we violate this in many places, but we should probably make fields immutable during render.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I want to perform it as late as possible, but overriding the getter behaviour is more internally consistent.
src/Forms/TimeField.php
Outdated
* | ||
* @var bool | ||
*/ | ||
protected $html5 = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, should this be true by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, it's a better default - I'll change.
src/Forms/TimeField.php
Outdated
@@ -140,8 +165,20 @@ protected function getFormatter() | |||
$this->getTimezone() | |||
); | |||
|
|||
// Don't invoke getDateFormat() directly to avoid infinite loop | |||
if ($this->timeFormat) { | |||
$isoFormat = 'HH:mm:ss'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DBTime::ISO_TIME
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/Forms/TimeField.php
Outdated
|
||
// Try to parse time without seconds, since that's a valid HTML5 submission format | ||
// See https://html.spec.whatwg.org/multipage/infrastructure.html#times | ||
if ($timestamp === false && $this->setHTML5(true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to use $this->getHTML5()
as a condition? This method shouldn't mutate the object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Derp derp
|
||
New `TimeField` methods replace `getConfig()` / `setConfig()` | ||
|
||
* `getTimeFormat()` / `setTimeFormat()` | ||
* `getLocale()` / `setLocale()` | ||
* `getClientConfig()` has been removed (in favour of `setHTML5()`) | ||
|
||
#### <a name="overview-template-removed"></a>Template and Form Removed API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add notes on the removal of MemberDatetimeOptionsetField
to this section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe mention DateField_View_JQuery
too here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -81,9 +80,6 @@ class Member extends DataObject implements TemplateGlobalProvider | |||
'Locale' => 'Varchar(6)', | |||
// handled in registerFailedLogin(), only used if $lock_out_after_incorrect_logins is set | |||
'FailedLoginCount' => 'Int', | |||
// In ISO format | |||
'DateFormat' => 'Varchar(30)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good riddance. :)
src/Security/Member.php
Outdated
return $format; | ||
} | ||
return $this->getDefaultDateFormat(); | ||
$format = $this->getDefaultDateFormat(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably just merge getDefaultDateFormat and getDateFormat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/Security/Member.php
Outdated
return $timeFormat; | ||
} | ||
return $this->getDefaultTimeFormat(); | ||
$format = $this->getDefaultTimeFormat(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, we may as well merge these. The other place getDefault* methods were called are gone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
d64c236
to
3b94d14
Compare
@chillu your tests seem broken. Do they pass locally? |
See #6626