/
MaskitoOptions
have optional parameters preprocessors
and postprocessors
. Both accept array of pure functions. These functions are triggered on every user's input ( beforeinput and input events). They provide an opportunity to modify value before / after the mask is applied.
Preprocessors and postprocessors accept different types of arguments but they have two important similarities:
Each preprocessor is a function that is called before mask is applied.
For example, if user types a new character, all preprocessors will be called first, and only then final value that they returned will be passed into the mask, and finally the mask will accept or reject new typed character and update actual value of the text field.
Preprocessor accepts two arguments:
elementState
and data
. Object of the same interface with updated or unchanged properties can be returned from the preprocessor. Preprocessor returns an objects of the same interface as the first argument.
Each postprocessor is a function that is called after the mask is applied. When all preprocessors are already called, all mask operations happened and the input's value is about to be updated. You can change everything manually inside a postprocessor.
Postprocessor accepts two arguments:
Postprocessor returns an objects of the same interface as the first argument.
With great power comes great responsibility!
Postprocessor is the final step before input's value update which gives a lot of flexibility. Use postprocessor wisely and return a valid value!
The Maskito team likes code decomposition and promotes it! Don't put all complex logic inside a single processor. Both parameters preprocessors
and postprocessors
accepts array of same type processors. Break your code into the several independent processors so that each processor implements only a single task.
The following sections are recommended to explore core concepts further: