Skip to content

BasisHub/basis-input-masking

Repository files navigation

BASIS Input Masking

Build StatusGitHubGitHub file size in bytesGitHub tag (latest by date)David

Demo | API

A small javascript library to force inputs masking using BBj supported masks

Installation

yarn add BasisHub/bbj-masks BasisHub/basis-input-masking npm install BasisHub/bbj-masks BasisHub/basis-input-masking 

Usage

<scriptsrc="node_modules/bbj-masks/dist/bbj-masks.min.js"></script><scriptsrc="node_modules/basis-input-masking/dist/basis-input-masking.js"></script>

Components

The library ships two components :

TextInput

The TextInput will wrap text inputs and apply the given bbj string mask. You can combine masks with patterns to get accurate validation. In case the input lives in a form then the masked and the unmasked values will be submitted when the form is submitted

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
iOS Safari
iOS Safari
Opera
Opera
IE11, Edgelast 2 versionslast 2 versionslast 2 versionslast 2 versionslast 2 versions
<!-- masked value is +(49) 156 610 110 20 --><inputclass="bbj-text-masked" name="test" id="test" value="4915661011020" data-mask="+(00) 000 000 000 00" /><script>document.addEventListener('DOMContentLoaded',function(e){newBasis.InputMasking.TextInput({onUpdate: (maskedValue,rawValue,input)=>{// do something},onInvalid: (err,input)=>{// do something},})})</script>

Options

Options can be passed via data attributes . For data attributes, append the option name to data-, as in data-mask

OptionDefaultDescription
maskThe bbj string mask @see BBj String Masks

NumberInput

The NumberInput will wrap text inputs and apply the given bbj number mask. In case the input lives in a form then the masked and the unmasked values will be submitted when the form is submitted

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
iOS Safari
iOS Safari
Opera
Opera
Edgelast 2 versionslast 2 versionslast 2 versionslast 2 versionslast 2 versions
<!-- masked value is 1,234 --><inputclass="bbj-number-masked" name="test" id="test" value="1234" data-mask="##,##0" /><script>document.addEventListener('DOMContentLoaded',function(e){newBasis.InputMasking.NumberInput({onUpdate: (maskedValue,rawValue,input)=>{// do something},onInvalid: (err,input)=>{// do something},})})</script>

Options

Options can be passed via data attributes . For data attributes, append the option name to data-, as in data-mask

OptionDefaultDescription
maskThe bbj number mask @see BBj Number Masks
minThe maximum value to accept for this input
maxThe minimum value to accept for this input
stepA stepping interval to use when using up and down arrows to adjust the value, as well as for validation
grouping-separator,a char which will be used as a grouping separator
decimal-separator.a char which will be used as a decimal separator
force-trailing-zerosfalseAffects the output by switching the way a mask with "#" characters in the trailing positions is filled. for example, the function NumberMask.mask(.10:"#.##") returns .10 instead of .1

License

Licensed under the MIT License.

Packages

No packages published