アイコン通知

このサンプルでは検証コントロールにおける検証結果をアイコン通知に設定する方法を説明します。アイコンの位置やカスタム表示などを変更することができます。

検証コントロールのアイコン通知機能について解説します。 概要 notify(またはdefaultNotify)プロパティのiconプロパティを使用することで、検証結果に応じたアイコンの表示可否(boolean)を設定できますが、このiconプロパティには、アイコンの配置位置や表示するアイコン画像のカスタマイズなどが可能です。 通知の位置 アイコン通知の表示位置は、directionプロパティから設定可能です。設定可能な値(IconDirection列挙体)は、以下の通りです。 値 説明 Inside 通知アイコンをコントロールの内側に表示します。 Outside 通知アイコンをコントロールの外側に表示します。(既定値) たとえば、通知アイコンをコントロールの外側に表示したい場合のサンプルコードは、以下の通りです。(iconプロパティの設定部分のみ抜粋) カスタムアイコン 以下の各プロパティを使用することで、アイコン通知で表示するアイコン画像を設定できます。これらのプロパティには画像リソースへのパスを設定します。 プロパティ名 説明 failIconSrc 検証が失敗したときのアイコンを設定します。 successIconSrc 検証が成功したときのアイコンを設定します。 なお、successIconSrcプロパティを設定する場合、successプロパティ内にアイコン通知の設定を含める必要があります。successプロパティを省略して、notify(またはdefaultNotify)プロパティ内に直接successIconSrcプロパティを設定しても、有効に動作しません。また、failIconSrcプロパティをsuccessプロパティ内で設定しても、有効に動作しません。 検証成功時には独自の通知アイコンをコントロールの外側に、検証失敗時には独自の通知アイコンをコントロールの内側に表示する場合のサンプルコードは、以下の通りです。(iconプロパティの設定部分のみ抜粋)
import '@mescius/inputman/CSS/gc.inputman-js.css'; import { InputMan } from '@mescius/inputman'; InputMan.appearanceStyle = InputMan.AppearanceStyle.Modern; document.getElementById('gcTextBox').className = 'margin'; const gcTextBox = new InputMan.GcTextBox(document.getElementById('gcTextBox')); const iconDirections = [ InputMan.IconDirection.Inside, InputMan.IconDirection.Outside ]; document.getElementById('direction').addEventListener('change', (e) => { update(); }); var validator; const update = () => { if (validator) { validator.destroy(); } validator = new GCIM.GcValidator({ items: [ { control: gcTextBox, ruleSet: [ { rule: InputMan.ValidateType.Required } ], } ], defaultNotify: false ? null : { icon: { direction: iconDirections[document.getElementById('direction').selectedIndex], failIconSrc: document.getElementById('iconSrc').checked ? '$IMDEMOROOT$/ja/samples/validator/notify/notifyIcon/img/exclamation.png' : '' } } }); validator.validate(); } update(); document.getElementById('iconSrc').addEventListener('change', update);
<!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="gcTextBox"> <table class="sample"> <tr> <th>通知の位置</th> <td> <select id="direction" class="update"> <option>内側</option> <option selected>外側</option> </select> </td> </tr> <tr> <th>カスタムアイコン</th> <td> <label><input type="checkbox" id="iconSrc" class="update">カスタムアイコンを表示</label><br> </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', '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' }, } });