日付時刻コントロールには、入力用カレンダーをドロップダウン表示することが可能です。ここでは、ドロップダウンカレンダーについて説明します。
概要
日付時刻コントロールのaddDropDownメソッドを実行して、第2引数にDropDownType.Calendarを指定すると、ドロップダウンボタンの押下により、カレンダーが表示されます。このドロップダウンカレンダーは、コントロールへの視覚的な日付入力を可能にする入力補助機能で、カレンダーの外観を自由に設定できるほか、休日の登録といったカスタマイズが可能です。 カレンダーの動作や外観、休日設定を行うには、getDropDownCalendarメソッドでGcCalendarコントロールを取得します。ドロップダウンカレンダーは、カレンダーコントロールとほぼ同等の機能を保持します。ドロップダウンカレンダーでサポートされていない機能は下記の2点です。
日付の複数選択
テンプレートの使用
ドロップダウンカレンダーの主な設定方法については、カレンダーコントロールの解説を参照してください。サンプルコードでは、カレンダーコントロールのコントロール名をドロップダウンカレンダーオブジェクトに置き換えてください。(例:gcCalendarをgcDateTime.getDropDownCalendar()に置き換える)
ドロップダウン操作
コントロールがフォーカスを取得したときに自動的にドロップダウンを開くには、引数にtrueを指定してsetAutoDropDownメソッドを実行します。
任意のタイミングで手動でドロップダウンを開くには、ドロップダウンウィンドウ(getDropDownWindowメソッドで取得します)のopenメソッドを実行します。また、ドロップダウンを開くにはcloseメソッドを実行します。
ドロップダウンボタン
ドロップダウンボタンの表示有無は、setDropDownButtonVisibleメソッドで設定することが可能です。引数をtrueに設定すると、ドロップダウンボタンが表示されます。(既定値はtrueです。)
ドロップダウンの方向
ドロップダウンは通常コントロールの下に表示されますが、コントロールの下にドロップダウンを表示できる十分なスペースがない場合は、ドロップダウンがコントロールの上に表示されます。ドロップダウンの表示スペースを判定するとき、既定ではWebページ本体(body要素)をコンテナとして扱いますが、setContainerメソッドで任意の要素をコンテナとして指定することも可能です。
import '@grapecity/inputman/CSS/gc.inputman-js.css';
import './styles.css';
import { InputMan } from '@grapecity/inputman';
const gcDateTime1 = new InputMan.GcDateTime(document.getElementById('gcDateTime1'), {
showDropDownButton: true,
dropDownConfig: {
dropDownType: InputMan.DateDropDownType.Calendar
},
container: document.getElementById('container1')
});
const gcDateTime2 = new InputMan.GcDateTime(document.getElementById('gcDateTime2'), {
showDropDownButton: true,
dropDownConfig: {
dropDownType: InputMan.DateDropDownType.Calendar
},
container: document.getElementById('container2')
});
document.getElementById('openOnFocus').addEventListener('change', (e) => {
gcDateTime1.setAutoDropDown(e.target.checked);
gcDateTime2.setAutoDropDown(e.target.checked);
});
document.getElementById('open').addEventListener('click', (e) => {
gcDateTime1.getDropDownWindow().open();
gcDateTime2.getDropDownWindow().open();
});
document.getElementById('close').addEventListener('click', (e) => {
gcDateTime1.getDropDownWindow().close();
gcDateTime2.getDropDownWindow().close();
});
document.getElementById('setDropDownButtonVisible').addEventListener('change', (e) => {
gcDateTime1.setDropDownButtonVisible(e.target.checked);
gcDateTime2.setDropDownButtonVisible(e.target.checked);
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>日付時刻コントロール - ドロップダウンカレンダー</title>
<!-- 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="flexbox">
<div id="container1">
<p>ドロップダウンが下に表示されます。</p>
<input id="gcDateTime1">
</div>
<div id="container2">
<p>ドロップダウンが上に表示されます。</p>
<input id="gcDateTime2">
</div>
</div>
<table class="sample">
<tr>
<th>フォーカス時のドロップダウン操作</th>
<td>
<label><input type="checkbox" id="openOnFocus">フォーカス時にドロップダウンを開く</label>
</td>
</tr>
<tr>
<th>コードによるドロップダウン操作</th>
<td>
<button id="open">ドロップダウンを開く</button>
<button id="close">ドロップダウンを閉じる</button>
</td>
</tr>
<tr>
<th>ドロップダウンボタンの表示</th>
<td>
<label><input type="checkbox" id="setDropDownButtonVisible" checked>ドロップダウンボタンを表示する</label>
</td>
</tr>
</table>
</body>
</html>
.flexbox {
display: flex;
flex-wrap: wrap;
}
.flexbox > div {
height: 300px;
width: 300px;
background-color: #f8f8f8;
}
#container2 > p {
margin-top: 220px;
}
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true
},
meta: {
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'@grapecity/inputman': 'npm:@grapecity/inputman/index.js',
'@grapecity/inputman/CSS': 'npm:@grapecity/inputman/CSS',
'css': 'npm:systemjs-plugin-css/css.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build': 'npm:systemjs-plugin-babel/systemjs-babel-browser.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'js'
},
"node_modules": {
defaultExtension: 'js'
},
}
});