InputDate Customization

You can customize the appearance of the InputDate and its drop-down calendar using CSS, or using the Calendar's formatItem event to customize the appearance of specific dates in the drop-down calendar. This sample customizes the weekends and holidays, and uses the controlTemplate property to change the InputDate's icon from a dropdown arrow to an calendar.

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wijmo from '@grapecity/wijmo'; import * as input from '@grapecity/wijmo.input'; import { getHoliday } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // change InpuDate icon to a calendar instead of a down arrow (applies to all InputDate controls) input.InputDate.controlTemplate = '<div style="position:relative" class="wj-template">' + '<div class="wj-input">' + '<div class="wj-input-group wj-input-btn-visible">' + '<input wj-part="input" type="text" class="wj-form-control" />' + '<span wj-part="btn" class="wj-input-group-btn" tabindex="-1">' + '<button class="wj-btn wj-btn-default" type="button" tabindex="-1">' + '<span class="wj-glyph-calendar"></span>' + '</button>' + '</span>' + '</div>' + '</div>' + '<div wj-part="dropdown" class="wj-content wj-dropdown-panel" ' + 'style="display:none;position:absolute;z-index:100">' + '</div>' + '</div>'; // // change the format used to show current month/year (affects all InputDate and Calendar controls) wijmo.culture.Globalize.calendar.patterns['y'] = 'MMMM yyyy'; // // the InputDate let theInputDate = new input.InputDate('#theInputDate', { valueChanged: () => showCurrentDate(theInputDate) }); showCurrentDate(theInputDate); // // format items in the InputDate's calendar (apply styles to weekends and holidays) theInputDate.calendar.formatItem.addHandler((sender, e) => { let weekday = e.data.getDay(), holiday = getHoliday(e.data); // wijmo.toggleClass(e.item, 'date-weekend', weekday == 0 || weekday == 6); wijmo.toggleClass(e.item, 'date-holiday', holiday != null); e.item.title = holiday || ''; }); // // show the currently selected date function showCurrentDate(ctrl) { var el = document.querySelector('#theInputDateOutput'); el.textContent = wijmo.Globalize.format(ctrl.value, 'D'); } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity InputDate Customization</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <input id="theInputDate"> <div> The current date is <b><span id="theInputDateOutput"></span></b>. </div> </div> </body> </html> let holidays = { '1/1': 'New Year\'s Day', '6/14': 'Flag Day', '7/4': 'Independence Day', '11/11': 'Veteran\'s Day', '12/25': 'Christmas Day', '1/3/1': 'Martin Luther King\'s Birthday', '2/3/1': 'Washington\'s Birthday', '5/3/6': 'Armed Forces Day', '9/1/1': 'Labor Day', '10/2/1': 'Columbus Day', '11/4/4': 'Thanksgiving Day' // fourth Thursday in November }; // // gets the holiday for a given date export function getHoliday(date) { let day = date.getDate(), month = date.getMonth() + 1, holiday = holidays[month + '/' + day]; // if (!holiday) { let weekDay = date.getDay(), weekNum = Math.floor((day - 1) / 7) + 1; // holiday = holidays[month + '/' + weekNum + '/' + weekDay]; } // return holiday; } .wj-calendar { max-width: 21em; } .wj-calendar .wj-header { color: white; background: #808080; } .wj-calendar .date-holiday:not(.wj-state-selected) { font-weight: bold; color: #008f22; background: #f0fff0; outline: 2pt solid #008f22; } .wj-calendar .date-weekend:not(.wj-state-selected) { background-color: #d8ffa6; } body { margin-bottom: 36px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wijmo from '@grapecity/wijmo'; import * as input from '@grapecity/wijmo.input'; // import { Component, enableProdMode, NgModule, Inject } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; import { DataService } from './app.data'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { constructor(@Inject(DataService) private dataService: DataService) { // change InpuDate icon to a calendar instead of a down arrow (applies to all InputDate controls) input.InputDate.controlTemplate = '<div style="position:relative" class="wj-template">' + '<div class="wj-input">' + '<div class="wj-input-group wj-input-btn-visible">' + '<input wj-part="input" type="text" class="wj-form-control" />' + '<span wj-part="btn" class="wj-input-group-btn" tabindex="-1">' + '<button class="wj-btn wj-btn-default" type="button" tabindex="-1">' + '<span class="wj-glyph-calendar"></span>' + '</button>' + '</span>' + '</div>' + '</div>' + '<div wj-part="dropdown" class="wj-content wj-dropdown-panel" ' + 'style="display:none;position:absolute;z-index:100">' + '</div>' + '</div>'; // // change the format used to show current month/year (affects all InputDate and Calendar controls) wijmo.culture.Globalize.calendar.patterns['y'] = 'MMMM yyyy'; } // customizeCalendar(calendar: input.Calendar) { calendar.formatItem.addHandler((sender: input.Calendar, e: input.FormatItemEventArgs) => { let weekday = e.data.getDay(), holiday = this.dataService.getHoliday(e.data); // wijmo.toggleClass(e.item, 'date-weekend', weekday == 0 || weekday == 6); wijmo.toggleClass(e.item, 'date-holiday', holiday != null); e.item.title = holiday || ''; }); } } // @NgModule({ imports: [WjInputModule, BrowserModule], declarations: [AppComponent], providers: [DataService], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity InputDate Customization</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <wj-input-date #theInputDate (initialized)="customizeCalendar(theInputDate.calendar)"></wj-input-date> <div> The current date is <b>{{ theInputDate.value | date:'fullDate'}}</b>. </div> </div> import { Injectable } from '@angular/core'; // @Injectable() export class DataService { // gets the holiday for a given date private readonly _holidays = { '1/1': 'New Year\'s Day', '6/14': 'Flag Day', '7/4': 'Independence Day', '11/11': 'Veteran\'s Day', '12/25': 'Christmas Day', '1/3/1': 'Martin Luther King\'s Birthday', // third Monday in January '2/3/1': 'Washington\'s Birthday', // third Monday in February '5/3/6': 'Armed Forces Day', // third Saturday in May '9/1/1': 'Labor Day', // first Monday in September '10/2/1': 'Columbus Day', // second Monday in October '11/4/4': 'Thanksgiving Day' // fourth Thursday in November }; // getHoliday(date: Date) { let day = date.getDate(), month = date.getMonth() + 1, holiday = this._holidays[month + '/' + day]; // if (!holiday) { let weekDay = date.getDay(), weekNum = Math.floor((day - 1) / 7) + 1; // holiday = this._holidays[month + '/' + weekNum + '/' + weekDay]; } // return holiday; } } .wj-calendar { max-width: 21em; } .wj-calendar .wj-header { color: white; background: #808080; } .wj-calendar .date-holiday:not(.wj-state-selected) { font-weight: bold; color: #008f22; background: #f0fff0; outline: 2pt solid #008f22; } .wj-calendar .date-weekend:not(.wj-state-selected) { background-color: #d8ffa6; } body { margin-bottom: 36px; } <template> <div class="container-fluid"> <wj-input-date :initialized="customizeCalendar"></wj-input-date> <div> The current date is <b>{{ theInputDate.value | formatDateTime }}</b>. </div> </div> </template> <script> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.core'; import '@grapecity/wijmo.vue2.input'; import * as input from '@grapecity/wijmo.input'; import { getHoliday } from './data'; let App = Vue.extend({ name: 'app', data: function () { return { theInputDate: {} } }, methods: { customizeCalendar: function(date){ this.theInputDate = date; date.calendar.formatItem.addHandler((sender, e) => { let weekday = e.data.getDay(), holiday = getHoliday(e.data); wijmo.toggleClass(e.item, 'date-weekend', weekday == 0 || weekday == 6); wijmo.toggleClass(e.item, 'date-holiday', holiday != null); e.item.title = holiday || ''; }); } }, filters: { formatDateTime: function(value){ return wijmo.Globalize.format(value, 'D'); } }, created: function(){ // change InpuDate icon to a calendar instead of a down arrow (applies to all InputDate controls) input.InputDate.controlTemplate = '<div style="position:relative" class="wj-template">' + '<div class="wj-input">' + '<div class="wj-input-group wj-input-btn-visible">' + '<input wj-part="input" type="text" class="wj-form-control" />' + '<span wj-part="btn" class="wj-input-group-btn" tabindex="-1">' + '<button class="wj-btn wj-btn-default" type="button" tabindex="-1">' + '<span class="wj-glyph-calendar"></span>' + '</button>' + '</span>' + '</div>' + '</div>' + '<div wj-part="dropdown" class="wj-content wj-dropdown-panel" ' + 'style="display:none;position:absolute;z-index:100">' + '</div>' + '</div>'; // // change the format used to show current month/year (affects all InputDate and Calendar controls) wijmo.culture.Globalize.calendar.patterns['y'] = 'MMMM yyyy'; } }) let vm = new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> .wj-calendar { max-width: 21em; } .wj-calendar .wj-header { color: white; background: #808080; } .wj-calendar .date-holiday:not(.wj-state-selected) { font-weight: bold; color: #008f22; background: #f0fff0; outline: 2pt solid #008f22; } .wj-calendar .date-weekend:not(.wj-state-selected) { background-color: #d8ffa6; } body { margin-bottom: 36px; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity InputDate Customization</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"></div> </body> </html> let holidays = { '1/1': 'New Year\'s Day', '6/14': 'Flag Day', '7/4': 'Independence Day', '11/11': 'Veteran\'s Day', '12/25': 'Christmas Day', '1/3/1': 'Martin Luther King\'s Birthday', '2/3/1': 'Washington\'s Birthday', '5/3/6': 'Armed Forces Day', '9/1/1': 'Labor Day', '10/2/1': 'Columbus Day', '11/4/4': 'Thanksgiving Day' // fourth Thursday in November }; // // gets the holiday for a given date export function getHoliday(date) { let day = date.getDate(), month = date.getMonth() + 1, holiday = holidays[month + '/' + day]; // if (!holiday) { let weekDay = date.getDay(), weekNum = Math.floor((day - 1) / 7) + 1; // holiday = holidays[month + '/' + weekNum + '/' + weekDay]; } // return holiday; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './app.css'; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as input from '@grapecity/wijmo.input'; import * as wijmo from '@grapecity/wijmo'; import * as wjInput from '@grapecity/wijmo.react.input'; import { getHoliday } from './data'; // class App extends React.Component { constructor(props) { super(props); // change InpuDate icon to a calendar instead of a down arrow (applies to all InputDate controls) input.InputDate.controlTemplate = '<div style="position:relative" class="wj-template">' + '<div class="wj-input">' + '<div class="wj-input-group wj-input-btn-visible">' + '<input wj-part="input" type="text" class="wj-form-control" />' + '<span wj-part="btn" class="wj-input-group-btn" tabindex="-1">' + '<button class="wj-btn wj-btn-default" type="button" tabindex="-1">' + '<span class="wj-glyph-calendar"></span>' + '</button>' + '</span>' + '</div>' + '</div>' + '<div wj-part="dropdown" class="wj-content wj-dropdown-panel" ' + 'style="display:none;position:absolute;z-index:100">' + '</div>' + '</div>'; // // change the format used to show current month/year (affects all InputDate and Calendar controls) wijmo.culture.Globalize.calendar.patterns['y'] = 'MMMM yyyy'; this.state = { value: null }; } render() { return <div className="container-fluid"> <wjInput.InputDate initialized={this._onInitialized.bind(this)} valueChanged={this._onValueChanged.bind(this)}> </wjInput.InputDate> <div> The current date is <b>{this._formatDateTime(this.state.value)}</b>. </div> </div>; } _onInitialized(sender) { this.setState({ value: sender.value }); sender.calendar.formatItem.addHandler((sender, e) => { let weekday = e.data.getDay(), holiday = getHoliday(e.data); wijmo.toggleClass(e.item, 'date-weekend', weekday == 0 || weekday == 6); wijmo.toggleClass(e.item, 'date-holiday', holiday != null); e.item.title = holiday || ''; }); } _formatDateTime(value) { return wijmo.Globalize.format(value, 'D'); } _onValueChanged(sender) { this.setState({ value: sender.value }); } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>AutoComplete</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> .wj-calendar { max-width: 21em; } .wj-calendar .wj-header { color: white; background: #808080; } .wj-calendar .date-holiday:not(.wj-state-selected) { font-weight: bold; color: #008f22; background: #f0fff0; outline: 2pt solid #008f22; } .wj-calendar .date-weekend:not(.wj-state-selected) { background-color: #d8ffa6; } body { margin-bottom: 36px; } const _holidays = { '1/1': 'New Year\'s Day', '6/14': 'Flag Day', '7/4': 'Independence Day', '11/11': 'Veteran\'s Day', '12/25': 'Christmas Day', '1/3/1': 'Martin Luther King\'s Birthday', '2/3/1': 'Washington\'s Birthday', '5/3/6': 'Armed Forces Day', '9/1/1': 'Labor Day', '10/2/1': 'Columbus Day', '11/4/4': 'Thanksgiving Day' // fourth Thursday in November }; export function getHoliday(date) { let day = date.getDate(), month = date.getMonth() + 1, holiday = _holidays[month + '/' + day]; // if (!holiday) { let weekDay = date.getDay(), weekNum = Math.floor((day - 1) / 7) + 1; // holiday = _holidays[month + '/' + weekNum + '/' + weekDay]; } // return holiday; }