Skip to content

Instantly share code, notes, and snippets.

@jodyHamilton
Created May 4, 2017 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jodyHamilton/15009b5314c5ff3482e3964d03bba0df to your computer and use it in GitHub Desktop.
Save jodyHamilton/15009b5314c5ff3482e3964d03bba0df to your computer and use it in GitHub Desktop.
Drupal 8 Date widget help text for browsers that dont support html5 date input.
// HTML5 date elements use the user's browser date format,
// but browsers that don't support it have a more confusing interface
// requiring help text.
Drupal.behaviors.DateHelp = {
attach: function (context, settings) {
if (Modernizr.inputtypes.date === false) {
// If there is no help text div, first add one.
$('div.field--widget-datetime-default:not(:has(.description))').each(function() {
$(this).find('input').after('<div class="description"></div>');
});
$('.field--widget-datetime-default .description').append(' Enter dates as yyyy-mm-dd.');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment