I. Overview
1.1 Requirement
How to pop up the error information and accordingly decide what to do next, instead of giving the validation messages in the built-in prompt dialogue box at the top-left corner of the FineReport?
1.2 Solution
When previewing the data entry, the system will trigger an After Validation event by default and return the parameter fr_verifyinfo which contains the return information about data validation. The parameter is an object that involves two attributes:
fr_verifyinfo.success: true/false, representing validation success or failure;
fr_verifyinfo.info: specific error information, which is an array object, for example, an error in A12 or B12.
II. Sample
2.1 Return a single error
1) The template is designed by taking the following steps:
2) Click [Template] >[Data Entry Attributes] >[Data Validation], and modify the built-in verify formula, as shown in the figure below:
If the value of D3 is less than or equal to 0, the Validation Error Information will show 0. If the value of D3 is greater than or equal to 1,000, the Validation Error Information will show 1.
3) Click [Template]>[Web Attributes]>[Data Entry Settings], choose [Individually set for the template], and add an After Validation event, as shown in the figure below:
Input the following JS codes:
if (fr_verifyinfo.success) {
alert("Successful inspection");
} else {
if (fr_verifyinfo.info == "D3:0") {
alert("Cost price is less than 0! ! !");
location.reload();
return false;
} else {
FR.Msg.confirm("warning", "The cost price is greater than 1000. Are you sure to submit?", function(result) {
if (result) {
contentPane.writeReport();
location.reload();
}
})
return false;
}
}
4)Save the template and click [Data Entry Preview].
Set the selling cost less than 0, as shown below:
Click [OK] to refresh the page. Set the selling cost greater than 1,000, as shown below:
2.2 Return several errors
1) Click [Template]>[Data Entry Attributes]>[Data Validation], and modify the built-in validation formula, as shown in the figure below:
If the value of D3 is less than or equal to 0, the Validation Error Information will show 0. If the value of E3 is less than or equal to 0, the Validation Error Information will show 1.
2) Click [Template]>[Web Attributes]>[Data Entry Settings], choose [Individually set for the template], and add an After Validation event, as shown in the figure below:
Input the following JS codes:
if (fr_verifyinfo.success) {
alert("Verify successfully");
} else {
for (var i = 0; i < fr_verifyinfo.info.length; i++) {
if (fr_verifyinfo.info[i] == "D3:0") {
//alert(fr_verifyinfo.info[i]);
alert("D3 cell check error");
} else if (fr_verifyinfo.info[i] == "E3:1") {
//alert(fr_verifyinfo.info[i]);
alert("E3 cell check error");
}
}
}
3) Save the template and click [Data Entry Preview].
Set the selling cost and other expenditures less than 0: