The ability to apply VALID and CONV properties to an EditLine control is a very powerful way to validate and format data entered in your applications, but this commonly relies on the user knowing how the data should be input without any visual clues being provided by the UI. Some formats like dates are fairly obvious, but others are not, and this can lead to user frustration when they are presented with a message box containing some cryptic and obscure error text from the depths of a custom Iconv() routine like this:
Cryptic IConv Message
In order to improve this situation the EditLine control now supports a new property called EDITMASK, which allows you to specify the input format of the data in a visual manner, along with the type of character that may be entered at each character position, thus reducing the probability of typing errors and thereby leading to a smoother user experience. For example here are two EditLine controls with an EDITMASK set for a phone number and a date respectively:
EDITMASK Phone and Date example
This property is a dynamic array composed of three fields:
<1> The Input Mask
<2> The Format Mask
<3> The Default Character
The Input Mask is what the user sees in the control when no data has been entered. The characters that they may edit are denoted by the “_” character, which is used as a placeholder. So, for a date the input mask could be “__/__/____”, meaning that they are allowed to edit the first two characters, the fourth and fifth character, and the last four characters. They will not be able to change either of the “\” characters.
The Format Mask controls the type of character that may be entered at each position where there is a placeholder “_” in the Input Mask. There should be one type specifier for each “_” character in the Input Mask, and a space character for the non-editable characters. The type specifiers are:
- “D” – A digit
- “d” – A digit or a space
- “C” – An alpha character
- “c” – An alpha character or space
- “A” – an alphanumeric character
- “a” – an alphanumeric character or space
- “X” – a hexadecimal character
- “x” – a hexadecimal character or space
- “*” – any printable character
- “+” – a “+” character, a “-” character, or space
So, for our date example we could have “dd dd dddd”. Note that the Format Mask must always be the same length as the Input Mask, otherwise the EDITMASK property will not work.
The Default Character is the character used for each invalid character in the user input. This defaults to an underscore (“_”).
To create the phone and date examples shown above you would set the following EDITMASK properties like so:
phoneMask = " ddd ddd dddd" |
: @fm : "(___) ___-____" |
: @fm : "_"
dateMask = "Dd Dd dddd" |
: @fm : "__/__/____" |
: @fm : "_"
objxArray = @window : ".EDL_PHONE"
propArray = "EDITMASK"
dataArray = phoneMask
objxArray := @rm : @window : ".EDL_DATE"
propArray := @rm : "EDITMASK"
dataArray := @rm : dateMask
call set_Property( objxArray, propArray, dataArray )
There are also some other supporting properties that can be used with the EDITMASK property:
This is a boolean property that affects how the TEXT property works when an EDITMASK property is applied. When set to TRUE getting the TEXT property only returns the characters that can be entered by the user, ignoring any of the non-placeholder characters in the Format Mask. By default this property is FALSE.
This is a boolean property that affects how the TEXT property works when an EDITMASK property is applied. When set to TRUE setting the TEXT property only updates the characters that can be entered by the user, ignoring any of the non-placeholder characters in the Format Mask. By default this property is FALSE.
This property is essentially a wrapper around the normal TEXT property, behaves as if both GETMASKEDCHARSONLY and SETMASKEDCHARSONLY were set to TRUE, so in effect it is a “shorthand” way of accessing and updating the text that can be edited.
In the example below the EditLines on the right contain the MASKEDTEXT property of the EditLines on the left:
(EDIT: 21 Aug 15 – Corrected EDITMASK member positions)
(Disclaimer: This article is based on preliminary information and may be subject to change in the final release version of OpenInsight 10).