マスク入力:全て入力

InputMaskコントロールは、マスクが完全に埋められたかどうかを示すmaskFullプロパティを公開します。このサンプルのコントロールは、maskFullプロパティがtrueになるまでコンテンツを赤で表示します。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wijmo from '@grapecity/wijmo'; import * as input from '@grapecity/wijmo.input'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { let theSSN = new input.InputMask('#theSSN', { mask: '000-00-0000', placeholder: '社会保障番号', isRequired: false, value: '', valueChanged: validateMask, lostFocus: lostFocus }); // let theZip = new input.InputMask('#theZip', { mask: '000-0000', placeholder: '郵便番号', isRequired: false, value: '', valueChanged: validateMask, lostFocus: lostFocus }); // let theZip4 = new input.InputMask('#theZip4', { mask: '00000-0000', placeholder: 'アメリカの郵便番号', isRequired: false, value: '', valueChanged: validateMask, lostFocus: lostFocus }); // let thePhone = new input.InputMask('#thePhone', { mask: '000-0000-0000', placeholder: '電話番号', isRequired: false, value: '', valueChanged: validateMask, lostFocus: lostFocus }); // // update 'state-invalid' class function validateMask(sender) { wijmo.toggleClass(sender.hostElement, 'state-invalid', !sender.maskFull); } // // clear masks that are not filled when losing focus var clearIncomplete = document.querySelector('#clearIncomplete'); function lostFocus(sender) { if (!sender.maskFull && !sender.isRequired && clearIncomplete.checked) { sender.value = ''; } } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity InputMask maskFull</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 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="container-fluid"> <div class="form-check"> <label for="clearIncomplete" class="form-check-label">未完了をクリア:</label> <input id="clearIncomplete" class="form-check-input" type="checkbox" checked="checked"> </div> <input id="theSSN"> <input id="theZip"> <input id="theZip4"> <input id="thePhone"> </div> </body> </html> .state-invalid { color: red; } label { width: 180px; text-align: right; } .wj-inputmask { margin-right: 3px; } body { margin-bottom: 24px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wijmo from '@grapecity/wijmo'; import * as input from '@grapecity/wijmo.input'; // import { Component, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { clearIncomplete = true; // validateMask(ctrl: input.InputMask) { wijmo.toggleClass(ctrl.hostElement, 'state-invalid', !ctrl.maskFull); } // lostFocus(ctrl: input.InputMask) { if (!ctrl.maskFull && !ctrl.isRequired && this.clearIncomplete) { ctrl.value = ''; } } } // @NgModule({ imports: [WjInputModule, FormsModule, BrowserModule], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity InputMask maskFull</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <div class="form-check"> <label for="clearIncomplete" class="form-check-label">未完了をクリア:</label> <input id="clearIncomplete" class="form-check-input" type="checkbox" [(ngModel)]="clearIncomplete"> </div> <wj-input-mask #theSSN [mask]="'000-00-0000'" [placeholder]="'社会保障番号'" [isRequired]="false" [value]="''" (valueChanged)="validateMask(theSSN)" (lostFocus)="lostFocus(theSSN)"></wj-input-mask> <wj-input-mask #theZip [mask]="'000-0000'" [placeholder]="'郵便番号'" [isRequired]="false" [value]="''" (valueChanged)="validateMask(theZip)" (lostFocus)="lostFocus(theZip)"></wj-input-mask> <wj-input-mask #theZip4 [mask]="'00000-0000'" [placeholder]="'アメリカの郵便番号'" [isRequired]="false" [value]="''" (valueChanged)="validateMask(theZip4)" (lostFocus)="lostFocus(theZip4)"></wj-input-mask> <wj-input-mask #thePhone [mask]="'000-0000-0000'" [placeholder]="'電話番号'" [isRequired]="false" [value]="''" (valueChanged)="validateMask(thePhone)" (lostFocus)="lostFocus(thePhone)"></wj-input-mask> </div> .state-invalid { color: red; } label { width: 180px; text-align: right; } .wj-inputmask { margin-right: 3px; } body { margin-bottom: 24px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './app.css'; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as wijmo from '@grapecity/wijmo'; import * as wjInput from '@grapecity/wijmo.react.input'; // class App extends React.Component { constructor(props) { super(props); this.validateMask = (ctrl) => { wijmo.toggleClass(ctrl.hostElement, 'state-invalid', !ctrl.maskFull); }; this.lostFocus = (ctrl) => { if (!ctrl.maskFull && !ctrl.isRequired && this.state.clearIncomplete) { ctrl.value = ''; } }; this.updateClearIncompleteStatus = (target) => { this.setState({ clearIncomplete: target.checked }); }; this.state = { clearIncomplete: true }; } render() { return <div className="container-fluid"> <div className="form-check"> <label htmlFor="clearIncomplete" className="form-check-label">未完了をクリア:</label> <input id="clearIncomplete" className="form-check-input" defaultChecked={true} type="checkbox" onChange={(e) => { this.updateClearIncompleteStatus(e.target); }}/> </div> <wjInput.InputMask placeholder="社会保障番号" mask="000-00-0000" isRequired={false} valueChanged={this.validateMask} lostFocus={this.lostFocus} value=""> </wjInput.InputMask> <wjInput.InputMask placeholder="郵便番号" mask="000-0000" isRequired={false} valueChanged={this.validateMask} lostFocus={this.lostFocus} value=""> </wjInput.InputMask> <wjInput.InputMask placeholder="アメリカの郵便番号" mask="00000-0000" isRequired={false} valueChanged={this.validateMask} lostFocus={this.lostFocus} value=""> </wjInput.InputMask> <wjInput.InputMask placeholder="電話番号" mask="000-0000-0000" isRequired={false} valueChanged={this.validateMask} lostFocus={this.lostFocus} value=""> </wjInput.InputMask> </div>; } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>AutoComplete</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 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 id="app"></div> </body> </html> .state-invalid { color: red; } label { width: 180px; text-align: right; } .wj-inputmask { margin-right: 3px; } body { margin-bottom: 24px; } <template> <div class="container-fluid"> <div class="form-check"> <label for="clearIncomplete" class="form-check-label">未完了をクリア:</label> <input id="clearIncomplete" class="form-check-input" type="checkbox" v-model="clearIncomplete"> </div> <wj-input-mask :mask="'000-00-0000'" :placeholder="'社会保障番号'" :isRequired="false" :value="''" :valueChanged="validateMask" :lostFocus="lostFocus"></wj-input-mask> <wj-input-mask :mask="'000-0000'" :placeholder="'郵便番号'" :isRequired="false" :value="''" :valueChanged="validateMask" :lostFocus="lostFocus"></wj-input-mask> <wj-input-mask :mask="'00000-0000'" :placeholder="'アメリカの郵便番号'" :isRequired="false" :value="''" :valueChanged="validateMask" :lostFocus="lostFocus"></wj-input-mask> <wj-input-mask :mask="'000-0000-0000'" :placeholder="'電話番号'" :isRequired="false" :value="''" :valueChanged="validateMask" :lostFocus="lostFocus"></wj-input-mask> </div> </template> <script> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.input'; let App = Vue.extend({ name: 'app', data: function(){ return { clearIncomplete: true } }, methods:{ validateMask: function(ctrl) { wijmo.toggleClass(ctrl.hostElement, 'state-invalid', !ctrl.maskFull); }, lostFocus: function(ctrl) { if (!ctrl.maskFull && !ctrl.isRequired && this.clearIncomplete) { ctrl.value = ''; } } } }) let vm = new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> .container-fluid .state-invalid { color: red; } label { width: 180px; text-align: right; } .container-fluid .wj-inputmask { margin-right: 3px; } body { margin-bottom: 24px; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity InputMask maskFull</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"></div> </body> </html>