InputManJSでは、コントロールへのアクションに応じてさまざまなイベントが発生します。リストコントロールで発生するイベントは、以下の通りです。
イベント名
説明
CheckedChanged
アイテムのチェック状態が変更されたときに発生します。
FocusedChanged
選択しているアイテムが変更されたときに発生します。
ItemClick
リストのアイテムをクリックしたときに発生します。
ItemsChanged
アイテムのリストが変更されたときに発生します。
LoadComplete
アイテムがサーバーからロードされたときに発生します。
SelectedChanged
選択しているアイテムが変更されたときに発生します。
import '@mescius/inputman/CSS/gc.inputman-js.css';
import { InputMan } from '@mescius/inputman';
import products from './data';
InputMan.appearanceStyle = InputMan.AppearanceStyle.Modern;
var gcListBox = new InputMan.GcListBox(document.getElementById('gcListBox'), {
items: products
});
// イベントハンドラ
gcListBox.addEventListener(
InputMan.GcListBoxEvent.CheckedChanged,
() => log('CheckedChanged')
);
gcListBox.addEventListener(
InputMan.GcListBoxEvent.FocusedChanged,
() => log('FocusedChanged')
);
gcListBox.addEventListener(
InputMan.GcListBoxEvent.ItemClick,
() => log('ItemClick')
);
gcListBox.addEventListener(
InputMan.GcListBoxEvent.ItemsChanged,
() => log('ItemsChanged')
);
gcListBox.addEventListener(
InputMan.GcListBoxEvent.LoadComplete,
() => log('LoadComplete')
);
gcListBox.addEventListener(
InputMan.GcListBoxEvent.SelectedChanged,
() => log('SelectedChanged')
);
// テキストボックスにログを出力
const log = (message) => {
var textarea = document.getElementById('log');
textarea.value += message + '\n';
textarea.scrollTop = textarea.scrollHeight;
}
<!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>
window.onload = function() {
System.import('./src/app');
}
</script>
</head>
<body>
<select id="gcListBox"></select><br><br>
イベント<br>
<textarea id="log" rows="10" cols="30"></textarea>
</body>
</html>
module.exports = [
'果汁100%オレンジ',
'果汁100%グレープ',
'果汁100%レモン',
'果汁100%ピーチ',
'コーヒーマイルド',
'コーヒービター'
];
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: {
'@mescius/inputman': 'npm:@mescius/inputman/index.js',
'@mescius/inputman/CSS': 'npm:@mescius/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'
},
}
});