JS Return Custom Error Message after Submitting Data

  • Last update:  2020-12-16
  • 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:

    III. Download the templates

    3.1 Return a single error

    1.cpt


    3.2 Return several errors

    2.cpt


    Attachment List


    Theme: Data Entry
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy