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.
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, you should customize the original attributes of the field in the data access class extension. To do this, perform the following actions:
- Open the field in the Data Class Editor, as described in To Customize a Field on the DAC Level.
- In the Customize Attributes box, select Append to Original.
- In the edit area below the box, add the PXDefault attribute without parameters.
- On the More menu (under Actions), click Edit Attributes.
- In the Attribute list of the Customize Attributes dialog box, which opens, click the PXUIField attribute to select it.
- In the parameter list, set the Required parameter to True.
- Click OK to exit the dialog box.The edit area of the editor must contain the following code:
[PXDefault] [PXCustomizeBaseAttribute(typeof(PXUIFieldAttribute), "Required", true)]
- Click Save on the editor toolbar to save your changes to the customization project.
UPDATE MyDac
SET NewField = 'Default Value'
WHERE NewField IS NULL
Because these scripts may be executed multiple times, you
must ensure that they do not corrupt any existing data. If you are dealing with complex
logic, you may need to write a customization plug-in instead.To Make a Custom Field Mandatory on the DAC Level
[PXDefault]
[PXUIField(..., Required = true)]
To Make a Field Mandatory on the Graph Level
- 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.
- 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) { }
- Click Save on the editor toolbar to save your changes to the customization project.