マスクコントロールが提供する独自の入力機能について解説します。
リテラル文字列を含まない値の取得と設定
getValueメソッドおよびsetValueメソッドを使えば、リテラル文字列とプロンプト文字列を除いたコントロール内の文字列を取得または設定できます。たとえば、テキストに「〒981-3205」が設定されているときには、getValueメソッドの値は「9813205」となります。
setValueメソッドで値が変更されると、その変更はgetDisplayTextメソッドとgetTextメソッドにも適用されます。また、getValueIsFullメソッドによって、すべてのフィールドに値が入力されているかどうかを確認することが可能です。
コピーや切り取りなどのユーザー操作によりクリップボードにリテラル文字を含まない値を渡すには、setClipContentメソッドでClipContent.ExcludeLiteralsに設定します。setClipContentメソッドの設定は、getSelectedTextメソッドから取得できる文字列にも適用されます。
なお、プロンプト文字列は、setClipContentメソッドの設定に関わらず常にクリップボードに渡されます。
改行コードの取り扱い
setAcceptsCrlfメソッドを使用してクリップボードへ改行を含む文字列をコピー、または貼り付けた場合の改行コードの扱いを設定できます。setAcceptsCrlfメソッドは、以下の3つの動作から選択します。既定値はCrLfMode.NoControlです。
値
説明
NoControl
改行コードはそのままでコピー、貼り付けを行います。
Filter
コピー、切り取り、または貼り付け文字列内にあるすべての改行コードを削除します。
Cut
コピー、切り取り、および貼り付け文字列内にある最初の改行コード以降の文字列を切り取ります。
タブ文字の取り扱い
acceptsTabCharプロパティを使用してクリップボードへタブ文字を含む文字列をコピー、または貼り付けた場合のタブ文字の扱いを設定できます。acceptsTabCharプロパティは、以下の3つの動作から選択します。既定値はTabCharMode.NoControlです。
値
説明
NoControl
タブ文字はそのままでコピー、貼り付けを行います。
Filter
コピー、切り取り、または貼り付け文字列内にあるすべてのタブ文字を削除します。
Cut
コピー、切り取り、および貼り付け文字列内にある最初のタブ文字以降の文字列を切り取ります。
import '@mescius/inputman/CSS/gc.inputman-js.css';
import { InputMan } from '@mescius/inputman';
InputMan.appearanceStyle = InputMan.AppearanceStyle.Modern;
const gcMask = new InputMan.GcMask(document.getElementById('gcMask'));
gcMask.setFormatPattern('〒\\D{3}-\\D{4}');
const rawValue = new InputMan.GcTextBox(document.getElementById('rawValue'));
document.getElementById('getValueBtn').addEventListener('click', () => {
rawValue.setText(gcMask.getValue());
});
document.getElementById('setValueBtn').addEventListener('click', (e) => {
gcMask.setValue(rawValue.getText());
});
document.getElementById('setAcceptsCrlf').addEventListener('change', (e) => {
gcMask.setAcceptsCrlf(crLfModes[e.target.selectedIndex]);
});
document.getElementById('acceptsTabChar').addEventListener('change', (e) => {
gcMask.acceptsTabChar = tabCharModes[e.target.selectedIndex]
});
const crLfModes = [
InputMan.CrLfMode.NoControl,
InputMan.CrLfMode.Filter,
InputMan.CrLfMode.Cut
];
const tabCharModes = [
InputMan.TabCharMode.NoControl,
InputMan.TabCharMode.Filter,
InputMan.TabCharMode.Cut
];
<!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>
<input id="gcMask">
<table class="sample">
<tr>
<th>リテラル文字列を含まない値</th>
<td>
<input type="text" id="rawValue">
<button id="getValueBtn">値の取得</button>
<button id="setValueBtn">値の設定</button>
</td>
</tr>
<tr>
<th>改行コードの扱い</th>
<td>
<select id="setAcceptsCrlf">
<option>そのまま使用</option>
<option>すべての改行コードを削除</option>
<option>改行コード以降の文字列を切り取り</option>
</select>
</td>
</tr>
<tr>
<th>タブ文字の扱い</th>
<td>
<select id="acceptsTabChar">
<option>そのまま使用</option>
<option>すべてのタブ文字を削除</option>
<option>タブ文字以降の文字列を切り取り</option>
</select>
</td>
</tr>
</table>
</body>
</html>
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',
'@mescius/inputman.richtexteditor': 'npm:@mescius/inputman.richtexteditor/index.js',
"@mescius/inputman.richtexteditor/CSS": "npm:@mescius/inputman.richtexteditor/CSS",
'@mescius/inputman.richtexteditor/JS/plugins/advlist': 'npm:@mescius/inputman.richtexteditor/JS/plugins/advlist/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/all': 'npm:@mescius/inputman.richtexteditor/JS/plugins/all/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/autosave': 'npm:@mescius/inputman.richtexteditor/JS/plugins/autosave/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/charmap': 'npm:@mescius/inputman.richtexteditor/JS/plugins/charmap/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/directionality': 'npm:@mescius/inputman.richtexteditor/JS/plugins/directionality/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/emoticons': 'npm:@mescius/inputman.richtexteditor/JS/plugins/emoticons/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/fullscreen': 'npm:@mescius/inputman.richtexteditor/JS/plugins/fullscreen/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/htmlcode': 'npm:@mescius/inputman.richtexteditor/JS/plugins/htmlcode/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/image': 'npm:@mescius/inputman.richtexteditor/JS/plugins/image/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/link': 'npm:@mescius/inputman.richtexteditor/JS/plugins/link/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/lists': 'npm:@mescius/inputman.richtexteditor/JS/plugins/lists/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/media': 'npm:@mescius/inputman.richtexteditor/JS/plugins/media/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/pagebreak': 'npm:@mescius/inputman.richtexteditor/JS/plugins/pagebreak/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/preview': 'npm:@mescius/inputman.richtexteditor/JS/plugins/preview/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/save': 'npm:@mescius/inputman.richtexteditor/JS/plugins/save/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/searchreplace': 'npm:@mescius/inputman.richtexteditor/JS/plugins/searchreplace/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/table': 'npm:@mescius/inputman.richtexteditor/JS/plugins/table/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/template': 'npm:@mescius/inputman.richtexteditor/JS/plugins/template/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/wordcount': 'npm:@mescius/inputman.richtexteditor/JS/plugins/wordcount/plugin.js',
'@mescius/inputman.comment': 'npm:@mescius/inputman.comment/index.js',
'@mescius/inputman.comment/CSS': 'npm:@mescius/inputman.comment/CSS',
'@mescius/wijmo': 'npm:@mescius/wijmo/index.js',
'@mescius/wijmo.styles': 'npm:@mescius/wijmo.styles',
'@mescius/wijmo.cultures': 'npm:@mescius/wijmo.cultures',
'@mescius/wijmo.input': 'npm:@mescius/wijmo.input/index.js',
'@mescius/wijmo.grid': 'npm:@mescius/wijmo.grid/index.js',
'@mescius/wijmo.nav': 'npm:@mescius/wijmo.nav/index.js',
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-resources-ja': 'npm:@mescius/spread-sheets-resources-ja/index.js',
'@mescius/spread-sheets/styles': 'npm:@mescius/spread-sheets/styles',
'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'
},
}
});