Wijmo 5 - Date and Time Input

by Manish Gupta

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"></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;
}

JavaScript

onload = function() {

    // the date/time being edited
    var theDate = new Date();
    
    // create InputDate control
    var inputDate = new wijmo.input.InputDate('#theInputDate', {
        min: new Date(2014, 8, 1),
        format: 'yyyy',
        selectionMode:2,
        showYearPicker:true,
        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
    var calendar = new wijmo.input.Calendar('#theCalendar', {
        min: new Date(2014, 8, 1),
        value: theDate
    });
    calendar.valueChanged.addHandler(valueChanged);
    
    // udpate theDate when the value changes in any of the controls
    function valueChanged(s, e) {
        theDate = s.value;
        inputDate.value = inputTime.value = calendar.value = theDate;
        document.getElementById('theDate').textContent = wijmo.Globalize.format(theDate, 'F');
    }
}