Skip to content
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

Conversation

chillu
Copy link
Member

@chillu chillu commented Apr 1, 2017

See #6626

@chillu chillu mentioned this pull request Apr 1, 2017
27 tasks
@@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DBDate::ISO_DATE

Copy link
Member Author

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!

*
* @var bool
*/
protected $html5 = false;
Copy link
Contributor

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?

Copy link
Member Author

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

$clientView->onBeforeRender();
if ($this->getHTML5()) {
// Browsers expect ISO 8601 dates, localisation is handled on the client
$this->setDateFormat('y-MM-dd');
Copy link
Contributor

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.

Copy link
Member Author

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.

*
* @var bool
*/
protected $html5 = false;
Copy link
Contributor

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?

Copy link
Member Author

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.

@@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DBTime::ISO_TIME

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


// 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)) {
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

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)',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good riddance. :)

return $format;
}
return $this->getDefaultDateFormat();
$format = $this->getDefaultDateFormat();
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return $timeFormat;
}
return $this->getDefaultTimeFormat();
$format = $this->getDefaultTimeFormat();
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@chillu chillu force-pushed the pulls/4.0/6626-remove-jquery-datepicker branch from d64c236 to 3b94d14 Compare April 3, 2017 00:11
@tractorcow
Copy link
Contributor

@chillu your tests seem broken. Do they pass locally?

@tractorcow tractorcow merged commit 32578e0 into silverstripe:master Apr 3, 2017
@tractorcow tractorcow deleted the pulls/4.0/6626-remove-jquery-datepicker branch April 3, 2017 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants