diff --git a/static/usage/v7/input/mask/angular/example_component_html.md b/static/usage/v7/input/mask/angular/example_component_html.md index f6d27b19558..2484e0c64e3 100644 --- a/static/usage/v7/input/mask/angular/example_component_html.md +++ b/static/usage/v7/input/mask/angular/example_component_html.md @@ -12,6 +12,7 @@ diff --git a/static/usage/v7/input/mask/angular/example_component_ts.md b/static/usage/v7/input/mask/angular/example_component_ts.md index 151a5bcac16..c7f0c898017 100644 --- a/static/usage/v7/input/mask/angular/example_component_ts.md +++ b/static/usage/v7/input/mask/angular/example_component_ts.md @@ -1,7 +1,7 @@ ```ts import { Component } from '@angular/core'; -import { MaskitoOptions, MaskitoElementPredicate } from '@maskito/core'; +import { MaskitoOptions, MaskitoElementPredicate, maskitoTransform } from '@maskito/core'; @Component({ selector: 'app-example', @@ -12,6 +12,9 @@ export class ExampleComponent { mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], }; + //If you need to set an initial value, you can use maskitoTransform to ensure the value is valid + myPhoneNumber = maskitoTransform('5555551212', this.phoneMask); + readonly cardMask: MaskitoOptions = { mask: [ ...Array(4).fill(/\d/), diff --git a/static/usage/v7/input/mask/demo.html b/static/usage/v7/input/mask/demo.html index b5fc734aae5..ef1938c39c0 100644 --- a/static/usage/v7/input/mask/demo.html +++ b/static/usage/v7/input/mask/demo.html @@ -8,8 +8,9 @@ @@ -39,10 +40,13 @@ async function initPhoneMask() { const ionInput = document.querySelector('#phone'); const nativeEl = await ionInput.getInputElement(); - - new window.Maskito(nativeEl, { + const phoneMaskOptions = { mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], - }); + }; + new window.Maskito(nativeEl, phoneMaskOptions); + + //If you need to set an initial value, you can use maskitoTransform to ensure the value is valid + ionInput.value = window.maskitoTransform('5555551212', phoneMaskOptions); } async function initCardMask() { diff --git a/static/usage/v7/input/mask/javascript/index_html.md b/static/usage/v7/input/mask/javascript/index_html.md index bf7aadd8150..9d2f90c90dd 100644 --- a/static/usage/v7/input/mask/javascript/index_html.md +++ b/static/usage/v7/input/mask/javascript/index_html.md @@ -12,10 +12,13 @@ async function initPhoneMask() { const ionInput = document.querySelector('#phone'); const nativeEl = await ionInput.getInputElement(); - - new window.Maskito(nativeEl, { + const phoneMaskOptions = { mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], - }); + }; + new window.Maskito(nativeEl, phoneMaskOptions); + + //If you need to set an initial value, you can use maskitoTransform to ensure the value is valid + ionInput.value = window.maskitoTransform('5555551212', phoneMaskOptions); } async function initCardMask() { diff --git a/static/usage/v7/input/mask/javascript/index_ts.md b/static/usage/v7/input/mask/javascript/index_ts.md index 89d38873488..8506f1714cd 100644 --- a/static/usage/v7/input/mask/javascript/index_ts.md +++ b/static/usage/v7/input/mask/javascript/index_ts.md @@ -1,7 +1,7 @@ ```ts import { defineCustomElements } from '@ionic/core/loader'; -import { Maskito } from '@maskito/core'; +import { Maskito, maskitoTransform } from '@maskito/core'; /* Core CSS required for Ionic components to work properly */ import '@ionic/core/css/core.css'; @@ -25,4 +25,5 @@ import './theme/variables.css'; defineCustomElements(); (window as any).Maskito = Maskito; +(window as any).maskitoTransform = maskitoTransform; ``` diff --git a/static/usage/v7/input/mask/react.md b/static/usage/v7/input/mask/react.md index 2b4d76902dc..0f6ec39cb4f 100644 --- a/static/usage/v7/input/mask/react.md +++ b/static/usage/v7/input/mask/react.md @@ -1,7 +1,8 @@ ```tsx -import React from 'react'; +import { useState } from 'react'; import { IonInput, IonItem, IonList } from '@ionic/react'; import { useMaskito } from '@maskito/react'; +import { MaskitoOptions, maskitoTransform } from '@maskito/core'; function Example() { const cardMask = useMaskito({ @@ -20,11 +21,13 @@ function Example() { }, }); - const phoneMask = useMaskito({ - options: { - mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], - }, - }); + const phoneMaskOptions: MaskitoOptions = { + mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], + }; + const phoneMask = useMaskito({ options: phoneMaskOptions }); + + //If you need to set an initial value, you can use maskitoTransform to ensure the value is valid + const [myPhoneNumber, setMyPhoneNumber] = useState(maskitoTransform('5555551212', phoneMaskOptions)); return ( @@ -48,6 +51,8 @@ function Example() { phoneMask(input); } }} + value={myPhoneNumber} + onIonInput={(e) => setMyPhoneNumber(e.detail.value || '')} label="US phone number" placeholder="+1 (xxx) xxx-xxxx" > diff --git a/static/usage/v7/input/mask/vue.md b/static/usage/v7/input/mask/vue.md index 14b96d0caee..815a2d51386 100644 --- a/static/usage/v7/input/mask/vue.md +++ b/static/usage/v7/input/mask/vue.md @@ -5,14 +5,21 @@ - + ``` diff --git a/static/usage/v8/input/mask/angular/example_component_html.md b/static/usage/v8/input/mask/angular/example_component_html.md index f6d27b19558..2484e0c64e3 100644 --- a/static/usage/v8/input/mask/angular/example_component_html.md +++ b/static/usage/v8/input/mask/angular/example_component_html.md @@ -12,6 +12,7 @@ diff --git a/static/usage/v8/input/mask/angular/example_component_ts.md b/static/usage/v8/input/mask/angular/example_component_ts.md index 1edb7f8c662..637f52b34b7 100644 --- a/static/usage/v8/input/mask/angular/example_component_ts.md +++ b/static/usage/v8/input/mask/angular/example_component_ts.md @@ -1,7 +1,7 @@ ```ts import { Component } from '@angular/core'; -import { MaskitoOptions, MaskitoElementPredicateAsync } from '@maskito/core'; +import { MaskitoOptions, MaskitoElementPredicateAsync, maskitoTransform } from '@maskito/core'; @Component({ selector: 'app-example', @@ -12,6 +12,9 @@ export class ExampleComponent { mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], }; + //If you need to set an initial value, you can use maskitoTransform to ensure the value is valid + myPhoneNumber = maskitoTransform('5555551212', this.phoneMask); + readonly cardMask: MaskitoOptions = { mask: [ ...Array(4).fill(/\d/), diff --git a/static/usage/v8/input/mask/demo.html b/static/usage/v8/input/mask/demo.html index d3f2598bea2..1d1de364389 100644 --- a/static/usage/v8/input/mask/demo.html +++ b/static/usage/v8/input/mask/demo.html @@ -8,8 +8,9 @@ @@ -39,10 +40,13 @@ async function initPhoneMask() { const ionInput = document.querySelector('#phone'); const nativeEl = await ionInput.getInputElement(); - - new window.Maskito(nativeEl, { + const phoneMaskOptions = { mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], - }); + }; + new window.Maskito(nativeEl, phoneMaskOptions); + + //If you need to set an initial value, you can use maskitoTransform to ensure the value is valid + ionInput.value = window.maskitoTransform('5555551212', phoneMaskOptions); } async function initCardMask() { diff --git a/static/usage/v8/input/mask/javascript/index_html.md b/static/usage/v8/input/mask/javascript/index_html.md index bf7aadd8150..9d2f90c90dd 100644 --- a/static/usage/v8/input/mask/javascript/index_html.md +++ b/static/usage/v8/input/mask/javascript/index_html.md @@ -12,10 +12,13 @@ async function initPhoneMask() { const ionInput = document.querySelector('#phone'); const nativeEl = await ionInput.getInputElement(); - - new window.Maskito(nativeEl, { + const phoneMaskOptions = { mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], - }); + }; + new window.Maskito(nativeEl, phoneMaskOptions); + + //If you need to set an initial value, you can use maskitoTransform to ensure the value is valid + ionInput.value = window.maskitoTransform('5555551212', phoneMaskOptions); } async function initCardMask() { diff --git a/static/usage/v8/input/mask/javascript/index_ts.md b/static/usage/v8/input/mask/javascript/index_ts.md index 89d38873488..8506f1714cd 100644 --- a/static/usage/v8/input/mask/javascript/index_ts.md +++ b/static/usage/v8/input/mask/javascript/index_ts.md @@ -1,7 +1,7 @@ ```ts import { defineCustomElements } from '@ionic/core/loader'; -import { Maskito } from '@maskito/core'; +import { Maskito, maskitoTransform } from '@maskito/core'; /* Core CSS required for Ionic components to work properly */ import '@ionic/core/css/core.css'; @@ -25,4 +25,5 @@ import './theme/variables.css'; defineCustomElements(); (window as any).Maskito = Maskito; +(window as any).maskitoTransform = maskitoTransform; ``` diff --git a/static/usage/v8/input/mask/react.md b/static/usage/v8/input/mask/react.md index 2b4d76902dc..539bebc0e12 100644 --- a/static/usage/v8/input/mask/react.md +++ b/static/usage/v8/input/mask/react.md @@ -20,11 +20,13 @@ function Example() { }, }); - const phoneMask = useMaskito({ - options: { - mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], - }, - }); + const phoneMaskOptions: MaskitoOptions = { + mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], + }; + const phoneMask = useMaskito({ options: phoneMaskOptions }); + + //If you need to set an initial value, you can use maskitoTransform to ensure the value is valid + const [myPhoneNumber, setMyPhoneNumber] = useState(maskitoTransform('5555551212', phoneMaskOptions)); return ( @@ -48,6 +50,8 @@ function Example() { phoneMask(input); } }} + value={myPhoneNumber} + onIonInput={(e) => setMyPhoneNumber(e.detail.value || '')} label="US phone number" placeholder="+1 (xxx) xxx-xxxx" > diff --git a/static/usage/v8/input/mask/vue.md b/static/usage/v8/input/mask/vue.md index 14b96d0caee..815a2d51386 100644 --- a/static/usage/v8/input/mask/vue.md +++ b/static/usage/v8/input/mask/vue.md @@ -5,14 +5,21 @@ - + ```