To Make a Field Mandatory

If a field is mandatory for input, the user has to specify a value for the field before saving the record that contains the field. To make a field mandatory for input, you use the PXDefault attribute without parameters. A mandatory field is marked by an asterisk (*) on the form to cue the reader that a value must be specified for it. To mark a control for a mandatory field with an asterisk, you set the Required parameter of the PXUIField attribute to true.

You can make an original or custom field mandatory and mark a control for the field with an asterisk on the DAC and graph levels. The following sections provide detailed information:

To Make an Original Field Mandatory on the DAC Level

To make an original field mandatory and mark the control for the field with an asterisk on multiple forms with an asterisk, you should customize the original attributes of the field in the data access class extension. To do this, perform the following actions:
  1. Open the field in the Data Class Editor, as described in To Customize a Field on the DAC Level.
  2. In the Customize Attributes box, select Append to Original.
  3. In the edit area below the box, add the PXDefault attribute without parameters.
  4. On the More menu (under Actions), click Edit Attributes.
  5. In the Attribute list of the Customize Attributes dialog box, which opens, click the PXUIField attribute to select it.
  6. In the parameter list, set the Required parameter to True.
  7. Click OK to exit the dialog box.
    The edit area of the editor must contain the following code:
    [PXDefault]
    [PXCustomizeBaseAttribute(typeof(PXUIFieldAttribute), "Required", true)]
  8. Click Save on the editor toolbar to save your changes to the customization project.

To Make a Custom Field Mandatory on the DAC Level

If you need to set a default value for a custom data field, you add the PXDefault attribute without parameters and set the Required parameter of the PXUIField attribute to True, as in the following code snippet.
[PXDefault]
[PXUIField(..., Required = true)]

To Make a Field Mandatory on the Graph Level

To make a field mandatory and mark the field with an asterisk for the field control used on a single form, you should customize the field attributes in the graph extension. To do this, perform the following actions:
  1. Create the code template that includes the field attributes and the DACName_FieldPropertyName_CacheAttached() event handler, which replaces the attributes within the graph, as described in To Customize a Field on the Graph Level.
  2. By using the Code editor, replace the original attributes in the template, as shown in the following code snippet.
    [PXDefault]
    [PXCustomizeBaseAttribute(typeof(PXUIFieldAttribute), "Required", true)]
    protected void DACName_FieldPropertyName_CacheAttached(PXCache cache)
    {
    }
  3. Click Save on the editor toolbar to save your changes to the customization project.