Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.2k
docs(input): input masking examples#2993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
8af47590e98782ba7a19fa27bbc4860713a8dad7c3d0cf7e1c81e699374b2c03def4a76e811ef06b82b6a209f34016c4292dd0e3f6704bca44acaf53c6444cf06a4f0ab0076a8e6c64c98231eb271435bd5bea9343da9317777a37ff7da42324145904ed6604f6201a0367ecbb5e7bbaec24dcfFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| ```ts | ||
| import { NgModule } from '@angular/core'; | ||
| import { FormsModule } from '@angular/forms'; | ||
| import { BrowserModule } from '@angular/platform-browser'; | ||
| import { IonicModule } from '@ionic/angular'; | ||
| import { AppComponent } from './app.component'; | ||
| import { ExampleComponent } from './example.component'; | ||
| import { MaskitoModule } from '@maskito/angular'; | ||
| @NgModule({ | ||
| imports: [BrowserModule, FormsModule, MaskitoModule, IonicModule.forRoot({})], | ||
| declarations: [AppComponent, ExampleComponent], | ||
| bootstrap: [AppComponent], | ||
| }) | ||
| export class AppModule {} | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| ```html | ||
| <ion-list> | ||
| <ion-item> | ||
| <ion-input | ||
| label="Card number" | ||
| placeholder="0000 0000 0000 0000" | ||
| [maskito]="cardMask" | ||
| [maskitoElement]="maskPredicate" | ||
| ></ion-input> | ||
| </ion-item> | ||
| <ion-item> | ||
| <ion-input | ||
| label="US phone number" | ||
| placeholder="+1 (xxx) xxx-xxxx" | ||
| [maskito]="phoneMask" | ||
| [maskitoElement]="maskPredicate" | ||
| ></ion-input> | ||
| </ion-item> | ||
| </ion-list> | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| ```ts | ||
| import { Component } from '@angular/core'; | ||
| import { MaskitoOptions, MaskitoElementPredicateAsync } from '@maskito/core'; | ||
| @Component({ | ||
| selector: 'app-example', | ||
| templateUrl: 'example.component.html', | ||
| }) | ||
| export class ExampleComponent { | ||
| readonly phoneMask: MaskitoOptions = { | ||
| mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], | ||
| }; | ||
| readonly cardMask: MaskitoOptions = { | ||
| mask: [ | ||
| ...Array(4).fill(/\d/), | ||
| ' ', | ||
| ...Array(4).fill(/\d/), | ||
| ' ', | ||
| ...Array(4).fill(/\d/), | ||
| ' ', | ||
| ...Array(4).fill(/\d/), | ||
| ' ', | ||
| ...Array(4).fill(/\d/), | ||
| ], | ||
| }; | ||
| readonly maskPredicate: MaskitoElementPredicateAsync = async (el) => (el as HTMLIonInputElement).getInputElement(); | ||
| } | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Input</title> | ||
| <link rel="stylesheet" href="../../../common.css" /> | ||
| <script src="../../../common.js"></script> | ||
| <script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@7/dist/ionic/ionic.esm.js"></script> | ||
| <script type="module"> | ||
| import { Maskito } from 'https://cdn.jsdelivr.net/npm/@maskito/core/index.esm.js'; | ||
| window.Maskito = Maskito; | ||
| </script> | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@7/css/ionic.bundle.css" /> | ||
| <style> | ||
| ion-list { | ||
| width: 100%; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <ion-app> | ||
| <ion-content> | ||
| <div class="container"> | ||
| <ion-list> | ||
| <ion-item> | ||
| <ion-input id="card" label="Card number" placeholder="0000 0000 0000 0000"></ion-input> | ||
| </ion-item> | ||
| <ion-item> | ||
| <ion-input id="phone" label="US phone number" placeholder="+1 (xxx) xxx-xxxx"></ion-input> | ||
| </ion-item> | ||
| </ion-list> | ||
| </div> | ||
| </ion-content> | ||
| </ion-app> | ||
| <script> | ||
| async function initPhoneMask() { | ||
| const ionInput = document.querySelector('#phone'); | ||
| const nativeEl = await ionInput.getInputElement(); | ||
| new window.Maskito(nativeEl, { | ||
| mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], | ||
| }); | ||
| } | ||
| async function initCardMask() { | ||
| const ionInput = document.querySelector('#card'); | ||
| const nativeEl = await ionInput.getInputElement(); | ||
| new window.Maskito(nativeEl, { | ||
| mask: [ | ||
| ...Array(4).fill(/\d/), | ||
| ' ', | ||
| ...Array(4).fill(/\d/), | ||
| ' ', | ||
| ...Array(4).fill(/\d/), | ||
| ' ', | ||
| ...Array(4).fill(/\d/), | ||
| ' ', | ||
| ...Array(4).fill(/\d/), | ||
| ], | ||
| }); | ||
| } | ||
| window.addEventListener('appload', () => { | ||
| initCardMask(); | ||
| initPhoneMask(); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import Playground from '@site/src/components/global/Playground'; | ||
| import javascript_index_html from './javascript/index_html.md'; | ||
| import javascript_index_ts from './javascript/index_ts.md'; | ||
| import react_main_tsx from './react.md'; | ||
| import vue_example_vue from './vue.md'; | ||
| import angular_app_module_ts from './angular/app_module_ts.md'; | ||
| import angular_example_component_html from './angular/example_component_html.md'; | ||
| import angular_example_component_ts from './angular/example_component_ts.md'; | ||
| <Playground | ||
| version="7" | ||
| code={{ | ||
| javascript: { | ||
| files: { | ||
| 'index.html': javascript_index_html, | ||
| 'index.ts': javascript_index_ts, | ||
| }, | ||
| dependencies: { | ||
| '@maskito/core': '^0.16.0', | ||
| }, | ||
| }, | ||
| react: { | ||
| files: { | ||
| 'src/main.tsx': react_main_tsx, | ||
| }, | ||
| dependencies: { | ||
| '@maskito/react': '^0.16.0', | ||
| '@maskito/core': '^0.16.0', | ||
| }, | ||
| }, | ||
| vue: { | ||
| files: { | ||
| 'src/components/Example.vue': vue_example_vue, | ||
| }, | ||
| dependencies: { | ||
| '@maskito/vue': '^0.16.0', | ||
| '@maskito/core': '^0.16.0', | ||
| }, | ||
| }, | ||
| angular: { | ||
| files: { | ||
| 'src/app/app.module.ts': angular_app_module_ts, | ||
| 'src/app/example.component.html': angular_example_component_html, | ||
| 'src/app/example.component.ts': angular_example_component_ts, | ||
| }, | ||
| dependencies: { | ||
| '@maskito/angular': '^0.16.0', | ||
| '@maskito/core': '^0.16.0', | ||
| }, | ||
| }, | ||
| }} | ||
| src="usage/v7/input/mask/demo.html" | ||
| size="300px" | ||
| /> |
sean-perkins marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. sean-perkins marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| ```html | ||
| <html> | ||
| <head> | ||
| <link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core@7/css/core.css" /> | ||
| <link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core@7/css/ionic.bundle.css" /> | ||
| </head> | ||
liamdebeasi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| <body> | ||
| <ion-app> | ||
| <ion-content class="ion-padding"> | ||
| <ion-list> | ||
| <ion-item> | ||
| <ion-input id="card" label="Card number" placeholder="0000 0000 0000 0000"></ion-input> | ||
| </ion-item> | ||
| <ion-item> | ||
| <ion-input id="phone" label="US phone number" placeholder="+1 (xxx) xxx-xxxx"></ion-input> | ||
| </ion-item> | ||
| </ion-list> | ||
| </ion-content> | ||
| <script> | ||
| async function initPhoneMask() { | ||
| const ionInput = document.querySelector('#phone'); | ||
| const nativeEl = await ionInput.getInputElement(); | ||
| new window.Maskito(nativeEl, { | ||
| mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], | ||
| }); | ||
| } | ||
| async function initCardMask() { | ||
| const ionInput = document.querySelector('#card'); | ||
| const nativeEl = await ionInput.getInputElement(); | ||
| new window.Maskito(nativeEl, { | ||
| mask: [ | ||
| ...Array(4).fill(/\d/), | ||
| ' ', | ||
| ...Array(4).fill(/\d/), | ||
| ' ', | ||
| ...Array(4).fill(/\d/), | ||
| ' ', | ||
| ...Array(4).fill(/\d/), | ||
| ' ', | ||
| ...Array(4).fill(/\d/), | ||
| ], | ||
| }); | ||
| } | ||
| window.addEventListener('appload', () => { | ||
| initCardMask(); | ||
| initPhoneMask(); | ||
| }); | ||
| </script> | ||
| </ion-app> | ||
| </body> | ||
| </html> | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| ```ts | ||
| import { defineCustomElements } from '@ionic/core/loader'; | ||
| import { Maskito } from '@maskito/core'; | ||
| /* Core CSS required for Ionic components to work properly */ | ||
| import '@ionic/core/css/core.css'; | ||
| /* Basic CSS for apps built with Ionic */ | ||
| import '@ionic/core/css/normalize.css'; | ||
| import '@ionic/core/css/structure.css'; | ||
| import '@ionic/core/css/typography.css'; | ||
| /* Optional CSS utils that can be commented out */ | ||
| import '@ionic/core/css/padding.css'; | ||
| import '@ionic/core/css/float-elements.css'; | ||
| import '@ionic/core/css/text-alignment.css'; | ||
| import '@ionic/core/css/text-transformation.css'; | ||
| import '@ionic/core/css/flex-utils.css'; | ||
| import '@ionic/core/css/display.css'; | ||
| /* Theme variables */ | ||
| import './theme/variables.css'; | ||
| defineCustomElements(); | ||
| (window as any).Maskito = Maskito; | ||
| ``` |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.