コンボコントロールでは、リストアイテムの中から複数のアイテムを同時に選択することができます。
概要
コンストラクタオプションのisMultiSelectをtrueに設定することで、ドロップダウン表示されるリストアイテムの中から複数のアイテムを同時に選択することが可能になります。
複数選択を可能にした場合、リストアイテムの左端にチェックボックスが表示されます。リストアイテムを複数列構成にした場合、チェックボックスは左端の列内に表示されます。
複数アイテムを選択した場合、コンボコントロール上にはセミコロン区切りで選択したアイテムが表示されます。
区切り文字を変更する場合には、multipleItemSeparatorプロパティに任意の区切り文字を設定します。
import '@mescius/inputman/CSS/gc.inputman-js.css';
import './styles.css';
import { InputMan } from '@mescius/inputman';
import products from './data';
InputMan.appearanceStyle = InputMan.AppearanceStyle.Modern;
const render = (isMultiSelect, multipleItemSeparator) => {
let container = document.getElementById('container');
container.innerHTML = '';
let gcComboBox = new InputMan.GcComboBox(container, {
items: products,
isMultiSelect,
multipleItemSeparator
});
}
render(true, ';');
let delimiter = new InputMan.GcTextBox(document.getElementById('delimiter'), {
text: ';',
maxLength: 1
});
delimiter.onTextChanged(() => {
render(document.getElementById('isMultiSelect').checked, delimiter.text)
})
document.getElementById('isMultiSelect')
.addEventListener('change', (e) => render(e.target.checked, delimiter.text));
<!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>
<div id="container"></div>
<table class="sample">
<tr>
<th>複数選択</th>
<td>
<label><input type="checkbox" id="isMultiSelect" checked>複数選択を許可</label>
</td>
</tr>
<tr>
<th>区切り文字に使用する文字</th>
<td><input type="text" id="delimiter"></td>
</tr>
</table>
</body>
</html>
body {
min-height: 220px;
}
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'
},
}
});