Actions

MediaWiki

Common.js: Difference between revisions

From hmis

No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
// Example of a DateTimeInputWidget
// Example of a DateTimeInputWidget
var dateTimeInput = new mw.widgets.datetime.DateTimeInputWidget({
// Convert Page Forms text fields with class 'datetime-local' into HTML5 datetime-local pickers
    // Configuration options can go here
mw.hook('pf.formReady').add(function () {
    type: 'datetime', // Can be 'date', 'time', or 'datetime'
  document.querySelectorAll('input.datetime-local').forEach(el => {
    // Other options like 'utc' (boolean) or 'timezone' (string)
    el.setAttribute('type', 'datetime-local');
});
  });
 
// Append the widget to an element in your HTML form
$( 'body' ).append( dateTimeInput.$element );
 
// Accessing the value
dateTimeInput.on( 'change', function () {
    var dateValue = dateTimeInput.getValue();
    console.log( 'Selected date and time: ' + dateValue );
});
});

Revision as of 08:57, November 4, 2025

/* Any JavaScript here will be loaded for all users on every page load. */
// Example of a DateTimeInputWidget
// Convert Page Forms text fields with class 'datetime-local' into HTML5 datetime-local pickers
mw.hook('pf.formReady').add(function () {
  document.querySelectorAll('input.datetime-local').forEach(el => {
    el.setAttribute('type', 'datetime-local');
  });
});