Validate Data
- Last UpdatedNov 15, 2023
- 2 minute read
The Grid widget allows you to perform validation at cell level. You can validate data when a user updates a value. Some of the validation rules are provided by default as part of the Grid widget's configuration file (BaseGrid_SampleData_conf.js), and include:
-
Limiting the number of character string value
-
Limiting the number of decimal places for numeric data fields
-
Required fields
You can use the default validation or you can perform validation through scripting outside of the widget using other controls. If you create external validation scripts, the Grid widget handles them through a boolean result flag. The following are example validation scripts that the Grid widget recognizes, which you can add to the On Cell Change event property of the widget:
validate = {}; validate.result=true; validate.Functionname = 'Validate';
control.findByXmlNode("grid1").widgetProperties.notify=JSON.stringify(validate);
validate = {}; validate.result=false; validate.Functionname = 'Validate';
control.findByXmlNode("grid1").widgetProperties.notify=JSON.stringify(validate);
In the example scripts, if the result is true, the widget accepts the new value. If the result is false, the cell value returns to its previous value.
Old and modified values
You can use the following example scripts to get the previous row and new cell values of the Grid with the On Cell Change event property of the widget.
Old row value
var oldval = (JSON.parse(event.oldvalue));
For example, if you want to get the previous row value of a uom_id column cell:
var uom = JSON.parse(oldval).uom_id;
Modified cell value
var modified = (JSON.parse(event.modifiedvalue));
For example, if you want to get the new cell value of a uom_id column cell:
var uom = JSON.parse(modified).uom_id;
Disabling default validation
If you want to do the validation outside the widget, remove or comment out the validation section in the code.
The highlighted validation section in the following screenshot is for validating the required fields and character string limit respectively.
Note: Character string limit validation works on edit mode and not on initial data load.

The validation for limiting the number of decimal places is added to one of the example fields. Search for the weightEditor line in the code, which serves as the placeholder code for limiting the number of decimal places.
