README
Numeric input
Framework-agnostic numeric input elements. This library was created after successive attempts at implementing some numeric input requirements using multiple libraries for the creation of masked inputs such as Inputmask and Text Mask. These libraries offer generic solutions for the creation of masked inputs; unfortunately, some of our requirements for numeric inputs do not fit well with the notion of masks. As such, when attempting to use these libraries we continuously felt the need to override or patch certain library-imposed behaviours. It was thus simpler to create a library tailored to our numeric input needs.
This library converts <input>
elements into numeric inputs which support the
following:
- Numbers have a set number of decimal places (scale) and begin to be written
from the right-most decimal place, i.e. if the number is set to have a scale
of
2
and the user types in1
, the resulting value is'0.01'
. - Numbers support an arbitrary number of leading zeroes, i.e. if the number is
set to have
4
leading zeroes and the user types in1
, the resulting value is'0001'
. - The numeric input may represent an integer or a floating number; this means
that the value
'0.01'
displayed in the input element may represent either the number1
(integer) or the number0.01
(float). Representing numbers as integers removes the risk of floating point errors. - Numeric inputs may set their minimum and maximum values which are validated as appropriate while the user is typing. Out of bound values may still be programmatically set on the numeric input.
- A number's signal may be toggled by typing
-
anywhere in the input element. - Prefixes and suffixes are supported, e.g. specifying a prefix of
'