To Configure an Input Mask and a Display Mask for a Field
In this topic, you can learn how to create a field on a form of an MYOB Acumatica Framework-based application so that its value is displayed in a specific format and how to govern what a user can enter as a value of this field. You can specify input and display masks for fields of the string and date and time types. For fields of the string type, you specify only the input mask, which defines both the format in which the user enters the value and the way the value is then displayed. For the date and time fields, you can specify different input and display masks.
To Specify an Input Mask and a Display Mask for a String Field
- In the data access class (DAC), add a new field or modify an existing
string
field as follows:- Add one of the string attributes (PXDBString or PXString) to the property field.
- Specify the value of the InputMask property of the attribute.
Use the following conventions to define the mask:
C
or&
: The user can enter any symbol.A
ora
: The user can enter any letter or digit.L
or?
: The user can enter only a letter.#
,0
, or9
: The user can enter only a digit.>
: All of the characters that follow this symbol should be in uppercase.<
: All of the characters that follow this symbol should be in lowercase.
The following example shows the use of the InputMask property.//Users can enter only digits. //If a user enters "1234567890", the value is displayed as "(123) 456-7890". [PXDBString(10, InputMask = "(###) ###-####")] [PXUIField(DisplayName = "Parameter 1")] public virtual string Parameter1 { get; set; }
Note: The value is stored in the database without any formatting characters. That is, for the code example above, if a user enters 1234567890, the field in the database for the corresponding record will contain the same value (1234567890).
- In the ASPX code of the form, add a new PXMaskEdit control or
modify the control that corresponds to the field so that it has the
PXMaskEdit type, as shown in the following code
example.
<px:PXMaskEdit ID="edParameter1" runat="server" DataField="Parameter1"/>
To Specify an Input and a Display Mask for a String Field at Runtime
To specify the input mask for a string field at runtime, use a SetInputMask method of the PXDBString or PXString attribute. You use the same conventions to define the mask as those described for the InputMask property in To Specify an Input Mask and a Display Mask for a String Field.
AccountMask
field is
changed at run
time.protected virtual void GLBudgetTree_IsGroup_FieldSelecting(PXCache sender,
PXFieldSelectingEventArgs e)
{
PXStringState strState = (PXStringState)sender.GetStateExt(
null, typeof(GLBudgetTree.accountID).Name);
PXDBStringAttribute.SetInputMask(sender,
typeof(GLBudgetTree.accountMask).Name,
strState.InputMask.Replace('#', 'C'));
}
To Specify an Input or a Display Mask for a Date and Time Field
- In the data access class (DAC), add a new field or modify an existing data and time
field as follows:
- Add one of the date and time attributes (PXDate, PXDateAndTime, PXDBDate, PXDBTime, or PXDBDateAndTime) to the property field.
- Specify the value of the InputMask or DisplayMask property of the attribute. Use the standard and custom date and time format strings.
The following example shows the use of the InputMask and DisplayMask properties.[PXDateAndTime(DisplayMask = "D", InputMask ="d")] [PXUIField(DisplayName = "Parameter 1")] public virtual DateTime? Parameter1 { get; set; }
- In the ASPX code of the form, add a new PXDateTimeEdit control or
modify the control that corresponds to the field so that it has the
PXDateTimeEdit type, as shown in the following code
example.
<px:PXDateTimeEdit ID="edParameter1" runat="server" DataField="Parameter1"/>
Note: You can change how the PXDateTimeEdit control is displayed (whether the control shows a calendar selector or a drop-down list with time values) by specifying the value of the TimeMode property. The following example causes the system to display the list of time values.<px:PXDateTimeEdit ID="edParameter1" runat="server" DataField="Parameter1" TimeMode="true"/>