Form Helper, for Angular application (for version 7 or over)
This is a simple mask lib with two single directives: a directive to allow field data entry from being just characters mapped by a regular expression and a directive to mask values, it works exclusively for numeric values.
Overview
https://lordazzi.github.io/ng-form-helper/
Installation
First execute the following command in the root folder of your angular application:
npm install ng-form-helper@latest --save
Then, you must import the library main module in your app.module, like this:
;;;;;
Usage
The masked field:
- Each 9 represents a number.
- The mask must finish with a nine.
- You should not put any number in the mask but nine, all other charactere are allowed.
- The library have not a mask for date but you can create your own using the mask 99/99/9999 and using angular validators to valid the given date.
The regexed field:
- It is very cool to block data entry with a regular expression, but it could be not nice for UX: the user could not see that the field just ignore his given value.
- Data entry blocked by a RegExp is nice for too large and unmasked number fields, like IMEI, ICCID or other large code.
- You should remember that the regular expression will block the field to containing a value that it disagrees with, so do not create a regular expression that represents, for example, a valid email, but write a regular expression that allows input of data of any character allowed in an email.
Customizing a field
In addition to the masks contained in this library, it also contains a class to make it easy to create custom fields in the angular.
The abstract directive FormFieldDirective
contain the logic to write data in ReactiveFormsModule, FormsModule and NgModel, you can extends it as the example below (the example is the code of formRegexedField):
;;;