Wijmo 5 - Date and Time Input

by Joel Parks

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.grapecity.com/wijmo/5.latest/styles/wijmo.min.css">
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.input.min.js"></script>
<div class="container">

  <h1>
    Date and Time input
  </h1>

  <p>
    Choose or edit the date and time using the
    <b>InputDate</b> and <b>InputTime</b> controls:</p>
  <div id="theInputDate"></div>
  <div id="theInputTime"></div>

  <p>
    Or pick the date from the <b>Calendar</b> 
    control:</p>
  <div id="theCalendar" class="has-ctx-menu"></div>

  <p>
    The current date/time value is 
    <b><span id="theDate"></span></b></p>
</div>

CSS

.wj-calendar {
    max-width: 300px;
}
.wj-control {
  margin-bottom: 6px;
}
body {
  margin-bottom: 24pt;
}
.wj-calendar .date-holiday {
    /* holidays in calendar */
    color: #008f22;
    outline: 2px solid #008f22;
}
.wj-calendar .date-weekend:not(.wj-state-selected) {
    /* weekends in calendar */
    background-color: #d8ffa6;
}

JavaScript

onload = function() {

    // the date/time being edited
    var theDate = new Date();
    
    // create the menu
    let menu = new wijmo.input.Menu(document.createElement('div'), {
        displayMemberPath: 'header',
        selectedValuePath: 'cmd',
        dropDownCssClass: 'ctx-menu',
        itemsSource: [
            { header: '<span class="glyphicon glyphicon-asterisk"></span>&nbsp;&nbsp;New', cmd: 'cmdNew' },
            { header: '<span class="glyphicon glyphicon-folder-open"></span>&nbsp;&nbsp;Open', cmd: 'cmdOpen' },
            { header: '<span class="glyphicon glyphicon-floppy-disk"></span>&nbsp;&nbsp;Save', cmd: 'cmdSave' },
            { header: '<span class="wj-separator"></span>' },
            { header: '<span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp;Exit', cmd: 'cmdExit' }
        ],
        itemClicked: () => {
            alert('Executing **' + menu.selectedValue + '** for element **' + menu.owner.id + '**');
        }
    });
    //
    // use it as a context menu for one or more elements
    let els = document.querySelectorAll('.has-ctx-menu');
    for (let i = 0; i < els.length; i++) {
        els[i].addEventListener('contextmenu', e => {
            menu.owner = wijmo.closest(e.target, '.has-ctx-menu');
            if (menu.owner) {
                e.preventDefault();
                menu.show(e);
            }
        }, true);
    }
    
    // create InputDate control
    var inputDate = new wijmo.input.InputDate('#theInputDate', {
        min: new Date(2014, 8, 1),
        format: 'M/d/yyyy',
        value: theDate
    });
    inputDate.valueChanged.addHandler(valueChanged);
    
    // create InputTime control
    var inputTime = new wijmo.input.InputTime('#theInputTime', {
        min: new Date(2014, 8, 1, 9, 0),
        max: new Date(2014, 8, 1, 17, 0),
        step: 15,
        format: 'h:mm tt',
        value: theDate
    });
    inputTime.valueChanged.addHandler(valueChanged);

    // create Calendar control
   ...