Masks
Configuring Masks in Grid Fields
To configure masks, go to the File Type settings, find the grid-type field you want to configure, and select the button to load the list of columns.
Go to the grid configuration screen, where you can create new columns or modify existing one
The attributes that can be defined for a grid column are as follows:
- Name: Identifies the column with a key.
- Label: The name displayed to the user when working with the grid.
- Length: Represents the space in pixels that the column occupies.
- Mask: Determines the allowable keyboard input values for each character.
- Validator: Allows adding a validation after the column value is entered.
- Key: Indicates that the column contains a value representing a key in a relationship with another subset of Files. If correct, it enables navigation to the related File.
- Sortable: Allows the user to sort the grid by this column.
- Read-Only: Disables interaction through the keyboard.
- Date: Indicates that the column contains dates in the format day/month/year (dd/mm/yyyy).
- Amount: Indicates that the column contains decimal numbers.
- Summable: Always displays (in the header) the sum of the column values for all rows in the grid.
It is important to note that the selection fields for defining "Date" and "Amount" are retained for compatibility with earlier versions, even if they can be determined using regular expressions (ER).
When selecting "Date" or "Amount," the "Mask" and "Validator" options are disabled. The "Summable" option remains selectable even if the column is not numeric, as it only activates when it finds numeric values, without affecting grid functionality if none are present.
Mask
Both the mask and the validator operate using a regular expression format (referred to as "RE" from here on).
The difference lies in that the mask must define an RE for each character it allows for input, separating them with "/,".
For example, if you want to allow only a tax ID (00-00000000-0), it should contain exactly 11 numeric digits. After the first two digits, a "-" is placed, followed by 8 digits, another "-", and ending with a single digit.
/[1-9]/,/\d/,-/,/\d/,/\d/,/\d/,/\d/,/\d/,/\d/,/\d/,/\d/,-/,/\d/
Each position starts with a forward slash "/" to indicate that this position is evaluated using an RE. In this example, we use "[1-9]" to specify that only values from 1 to 9 are allowed. We close the position with "/," to indicate moving to the next position.
In this example, the subsequent positions also use the RE "\d," which signifies a digit from 0 to 9.
It is important to note that, in the third and twelfth positions, we simply want a hyphen ("-"). Therefore, we do not start these positions with a forward slash "/" since they are not REs. This indicates that we allow only the hyphen ("-") in these positions.
Validator
This function allows you to validate the entire field upon exiting it. There are situations where defining a mask is complex, but an overall RE (regular expression) can be used. It alerts the user once the value is entered.
Continuing with the tax ID example, an expression like the following can be used:
^(20|27|23|24|25|26|30)-\d\d\d\d\d\d\d\d-\d
This RE is interpreted as follows: It can only start with the values 20, 27, 23, 24, 25, 26, or 30. Then a "-" is entered, followed by 8 digits (0 to 9), another "-", and finally a single digit (0 to 9).
It is similar to the previous example but provides greater control by allowing only specific numbers at the beginning.
There is no single RE to determine a value; multiple expressions can be used, and you must choose the most appropriate one. You can use tools like regex101.com for assistance.
Preloading Masks and Validators
As you identify common field types, you can save them in Netcontent for use in future implementations.
This is done by loading the "NC_CamposMascaras" table. Entries can only be added through the database.
- [CampoMascaraId] is an auto-increment field that provides a unique ID for each entry.
- [CampoTipo] is the identifier for the field type for which the mask is defined, such as 'Tax ID,' 'Email,' etc.
This value is presented when the format is not met, helping to contextualize the error. Therefore, when used, the value is concatenated at the beginning of the RE.
TaxId=>/[1-9]/,/\d/,-/,/\d/,/\d/,/\d/,/\d/,/\d/,/\d/,/\d/,/\d/,-/,/\d/
[[CampoMascara] is the RE string separated by "/," as seen previously.
[CampoValidador] is the RE string, as described earlier.
Having these expressions preloaded simplifies the definition of columns and fields in the File Type, as they are readily available for use.
They are simply shortcuts, as you can define your own REs or edit them.
Created with the Personal Edition of HelpNDoc: Revolutionize Your Documentation Review with HelpNDoc's Project Analyzer