/
Plugins are functions that are called with input/textarea element and mask options as arguments upon mask initialization. They can optionally return cleanup logic and allow you to extend mask with arbitrary additional behavior.
Let's explore this concept by solving an oversimplified task.
Imagine that you've created a mask to allow users entering only number with decimal part. If you explored documentation section "Mask expression" , it is piece of cake for you – everything is achieved by a base knowledge of RegExp
and a few code lines:
It works fine, users and your boss are almost completely satisfied. The last desired detail - no empty integer part on blur.
For example, imagine that you have the such textfield:
User sets caret before point => press Backspace => blur textfield. The result is following:
Looks not perfect, right? You need to "send signal" for users that the such incomplete value will be interpreted as 0.23
in your system. One way to do it – pads leading point with zero on blur event. Let's use the plugin for achieve it!
Good job! Now, you are ready to create your own plugin. Explore the result in action (the created mask is applied to the textfield below):
The following sections are recommended to explore core concepts further: