I am testing Scheduler with the site's default date format set to dd/mm/yyyy

However the date field placeholder text is displayed as mm/dd/yyyy.

The text underneath the date field reads:

"Format: Wed, 09/14/2016 - 11:24 or 14-09-2016 11:24:30. The default time is Wed, 09/14/2016 - 00:00"

This potentially could be quite confusing for users.

Comments

Dave Gray created an issue. See original summary.

Dave Gray’s picture

A quick follow up on the initial report. The placeholder text also stays as mm/dd/yyyy when a different date format value is set in the Scheduler config screen:
/admin/config/content/scheduler

Cheers

Dave Gray’s picture

Continuing to explore this one. I'll include findings to help others with the same issue.

The Scheduler widget uses the HTML5 date input type which is now in Drupal 8 core for use for date fields:
https://www.drupal.org/node/1496632

This is supported differently from browsers to browser, see:
http://www.html5tutorial.info/html5-date.php

In Chrome and Opera it seems like the date format that is shown depends on the default date format and language set in the browser and or browsing device.

Firefox just presents the default Y-m-d

Once UK English was set as the default language in both Chrome and OXS then the date format was shown in an appropriate regional format.

An interesting investigation, but I wonder how many international browser users are just using US English as a default without bothering to configure a regional alternative. I imagine not many non technical users would know where to change this.

It would be nice to figure out a way to present date formats in a date input field that doesn't depend on browser or device config.

On further searching it looks like:
https://www.previousnext.com.au/blog/making-drupal-8-datetime-widgets-use-human-formats

Might offer some clues to a way forward.

jonathan1055’s picture

Hi Dave,
Thanks for bringing this as an issue and for all your investigations. Yes, in Drupal7 we had full control over the date formatting and display, but the new date widgets have taken some of that away (at least in our current implementation).

It would be nice to figure out a way to present date formats in a date input field that doesn't depend on browser or device config.

Yes, I agree. I've also been concerned that we allow admins to set the date format, but do not actually use it any more (not in the way we did in 7.x) because we no longer have the ability to enter plain text. I am not sure if this was a design decision in the early days of converting Scheduler to 8.x or whether it simply fell off as we started using the date widget.

The issues #2490570: Validate that the 'publish on' value matches the expected format and #2490578: Validate that the 'unpublish on' value matches the expected format are in limbo until we decide what to do about text entry. If you have any ideas I'd be very happy to hear them.

Dave Gray’s picture

Hi Johnathan

I'm very used to the amount of fine control over dates in D7 so the D8 implementation caught me on the hop a bit.

A lot of my work is done with organisations with a very low level of technical know how. I think that the date input field is not as usable as it could be.

Many people won't know if they click on the tiny arrow then a datepicker will then pop up. Of course this is Chrome's implementation but the UI could be better.

Ironically I think the Firefox fallback to the jQuery UI's datepicker on field focus may well be easier for some.

Thanks for responding.

Dave

jonathan1055’s picture

Thanks for you investigations, Dave.

See also #2853263: Date field hints do not match configured date format in all browsers which was started in the Scheduler queue but has just been moved to Core Datetime module.

Do you think there is anything we (in Scheduler) need to do about this? I don't think there is actually any fault in our code, but could it be improved somehow?

Jonathan

jonathan1055’s picture

Status: Active » Closed (duplicate)
Related issues: +#2791693: Remove sample date from date field error message and title attribute

The core issue #2791693: Remove sample date from date field error message and title attribute covers this generic problem. I think we can close this on the Scheduler queue now.

jonathan1055’s picture

Title: Date field placeholder text doesn't reflect default date format » Date field placeholder text doesn't reflect date format defined in admin settings
Status: Closed (duplicate) » Needs work

Actually, we should do something in Scheduler. Currently we allow admins to select a datetime format but this is ignored by the HTML5 date input widget. Either (a) we should make modifications such as https://www.previousnext.com.au/blog/making-drupal-8-datetime-widgets-us..., or (b) remove the admin-defined date format altogether and use ISO8601 format YYYY-MM-DD without choice.

interx’s picture

I stumbled on exactly the same problem and came to the same conclusion before finding this post.

My site users have a system locale with a different date notation then what's configured as Date format in config. It is misleading to display a format notation in the description if that is not valid.

I think the date formatting feature should be removed entirely. All scheduler needs to know is that an RFC 3339 date is received from the browser. It always works, always returns correct data, and always gives the same UI everywhere.

Solutions that try to fix HTML date fields client-side should be in a separate contrib module. Doesn't seem to be a core feature of the scheduler module though. But that way they can be applied on all date fields on a site. In my experience, these fixes are a can of worms to get working on all devices in all configurations and not worth the hassle :)

jonathan1055’s picture

Title: Date field placeholder text doesn't reflect date format defined in admin settings » Date field placeholder text doesn't reflect date format defined in admin settings - hardcode the format

Hi interX,

I think the date formatting feature should be removed entirely. All scheduler needs to know is that an RFC 3339 date is received from the browser.

Yes, I have been thinking about this, and was coming to the same conclusion. In 7.x the Scheduler date format was important because we allowed text entry (if the date popup calendar was not installed) but in 8.x this is in core and we do not have any text entry field. Removing the admin-defined format and removing the text hints we add should simplify things.

Jonathan

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new27.83 KB

OK, here is a first attempt at getting rid of the configurable date format. For the time being I have left it as a config item, and the form displays the value but it cannot be altered. In future this may disappear from the form altogether. Summary of the changes in this patch:

  • scheduler.install has an update function to set the formats to default, to cater for users who are upgrading from an ealier release of Scheduler
  • scheduler.module removes the example date/time from the field entry description (as this was the cause of the problem) and replaces it with a fixed message 'enter and date or date and time' or 'enter a date' depending on whether the date-only option is enabled
  • hook_node_validate() is already redundant so is now deleted - see change record node/2420295
  • The message on saving a scheduled node uses 'long' format instead of the custom scheduler format
  • In scheduler_preprocess_node() the values are now formatted with 'long' instead of the custom scheduler format
  • In SchedulerAdminForm.php the admin form has the field disabled with the description explaining this
  • function validateForm() has a large chunk of code removed, as we no longer need to check the admin input format
  • function submitForm() no longer needs to save the format values to config, nor give any message about the date part and time part
  • functions getTimeOnlyFormat() and getDateOnlyFormat() are no longer required and are deleted
  • SchedulerAdminSettingsTest.php did not have much left after removing the format testing, so it now does the admin part of DefaultTimeTest, which makes sense as this is an admin setting
  • SchedulerDefaultTimeTest.php now just deals with the user/content side of default time functionality, not the admin settings. A few extra assertions have been added, and the function tidied up making re-use of $date_formatter
  • In SchedulerPastDatesTest.php, the publish_on value is checked directly in the $node not via the display message on saving the node

This change is removing some functionality, but as we can no longer control the date widget in HTML5 like we could back in 7.x I think we have to live with the reduced configurability, for the sake of not confusing our users. We could replace this with a setting to choose a date format from the existing site formats, for use in the messages on node save and in the formatted values stored in hook_node_presave. That gives back site builders some control.

All feedback is welcome, as this is quite a major change.

Jonathan

interx’s picture

Thanks for this. The patch works fine form me.

Just some minor notes:

  • The returned string in scheduler_update_8001 should be translatable.
  • When entering an invalid date, you get an error like "The Publish on date is invalid. Please enter a date in the format 2017-06-26 12:53:11.". This doesn't match my input format. Unfortunately this is due to the core issue and probably not under your control.
jonathan1055’s picture

Thanks for the review and test. I will add t( ) to the return string.

As for the validation message, yes this is not within our control. It was the same when we had a configurable scheduler format, so it is no worse now. The code in core is http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Datetime/Ele...
Some background is in #501428: Date and time field type in core

  • jonathan1055 committed 492e681 on 8.x-1.x
    Issue #2799869 by jonathan1055, Dave Gray, interX: Date field...
jonathan1055’s picture

Status: Needs review » Fixed

I decided to go for this, and get it committed. Need to get it done, so that we can move on to release rc2

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.